Closed fundon closed 1 year ago
cc #26
@adriangb In this case:
Router(
{
"/users": Router(
{
"": users_endpoint,
"/:name": user_endpoint,
}
)
)
Can the sub-router get the prefix path /users
?
Not easily. That same instance could be used somewhere else as well.
I'm realizing I may have misunderstood. Just to clarify, I don't think the nested router should know/need to know that it is mounted under the prefix "/users"
.
With the example you gave I think the routing should be as follows:
/users -> Some(users_endpoint)
/users/ -> None
/users/abc123 -> Some(user_endpoint)
In writing, empty string can be used, but a full path can be assembled at the end.
Pseudo codes:
sub_router.path = ''
sub_router.routes = ['', '/:name']
parent_router.path = '/users'
parent_router.mount(sub_router)
fn mount(sub_router) {
for route in sub_router.routes {
let path = parent_router.path + route
tree.insert(path)
}
}
Yeah that’s one way to do it. It’s nice to be able to support the version where the parent router doesn’t need to introspect into itself children
19
@adriangb try this branch