蓝图路由简单点说可以认为先给路由设置一个根目录,然后在该根目录下设置子路由,比如:
设置蓝图路由为/user/,然后添加子路由add, delete,那么总的路由相当于:
/user/add和/user/delete
看一下Crow的实现:
#define CROW_ROUTE(app, url) app.template route<crow::black_magic::get_parameter_tag(url)>(url)#define CROW_BP_ROUTE(blueprint, url) blueprint.new_rule_tagged<crow::black_magic::get_parameter_tag(url)>(url)
可以看到CROW_BP_ROUTE跟CROW_ROUTE还是很像的
其第一个参数是一个blueprint对象
class Blueprint
{
public:Blueprint(const std::string& prefix):prefix_(prefix){};template<uint64_t N>typename black_magic::arguments<N>::type::template rebind<TaggedRule>& new_rule_tagged(std::string&& rule){std::string new_rule = std::move(rule);new_rule = '/' + prefix_ + new_rule;using Rule