Path segment matching for nested routers.
Define your routes:
rust
fn route_list_1() -> RouteList {
let sub = RouteList {
routes: vec![Route {
path: ":id".to_string(),
next_routes: None,
}],
};
let root = RouteList {
routes: vec![
Route {
path: ":id".to_string(),
next_routes: Some(sub.clone()),
},
Route {
path: "about".to_string(),
next_routes: None,
},
],
};
root
}
Use the two routers:
```rust let root = routelist1();
let absolutepath = "/123/456"; let relativepath = &absolute_path[1..];
let RouteOutput { subpath, route, params, } = root.route(relativepath).unwrap(); asserteq!(route.path, ":id"); asserteq!(params.get("id"), Some(&"123".to_string()));
// Your business logic here for the first route
let sub = route.nextroutes.asref().unwrap();
let RouteOutput { subpath, route, params, } = sub.route(&subpath.unwrap()).unwrap(); asserteq!(route.path, ":id"); asserteq!(params.get("id"), Some(&"456".tostring())); asserteq!(sub_path, None);
// Your business logic here for the second route ```
Route::path
should not capture wildcard with name "_sub_path"
(crate::SUB_PATH_WILDCARD_NAME
).