-
-
Notifications
You must be signed in to change notification settings - Fork 711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting trailing_slash=Strict does not work with nested Routes #2624
Comments
I will note that I am now aware of the planned changes in leptos 0.7 will involve refactoring how paths are done. I am wondering if there will be ways to fine-tune control over |
Actually, there is another problem (maybe again with axum) - I am following through this example, following the example with fallback:
It seems the |
Not directly related, but still kind of related as this is still part of the The workaround for now that I've used is something like:
I use
The generated anchor will have the |
Okay, now that the #[component(transparent)]
pub fn ItemRoutes() -> impl IntoView {
view! {
<Route path="item" view=|| view! { "pre" <Outlet/> "post" }>
<Route path="/" view=ItemListing/>
<Route path="/:id" view=ItemView/>
</Route>
}
}
#[component]
fn ItemListing() -> impl IntoView {
view! {
<h1>Listing of items</h1>
<ul>
<li><A href="/item/1">"Item 1"</A></li>
<li><A href="/item/2">"Item 2"</A></li>
</ul>
}
}
#[component]
fn ItemView() -> impl IntoView {
let params = use_params_map();
// this not follow documented syntax either as that doesn't work
let id = move || {
params.get().get("id").cloned().unwrap_or_default()
};
view! {
<h1>Viewing item {id}</h1>
}
} This shows #[component]
pub fn ItemRoutes() -> impl MatchNestedRoutes<Dom> + Clone {
view! {
<ParentRoute path=StaticSegment("item") view=|| view! { "pre" <Outlet/> "post" }>
<Route path=StaticSegment("/") view=ItemListing/>
<Route path=ParamSegment("id") view=ItemView/>
</ParentRoute>
}
}
#[component]
fn ItemListing() -> impl IntoView {
view! {
<h1>Listing of items</h1>
<ul>
<li><A href="/item/1">"Item 1"</A></li>
<li><A href="/item/2">"Item 2"</A></li>
</ul>
}
}
#[component]
fn ItemView() -> impl IntoView {
let params = use_params_map();
let id = move || params.with(|params| params.get("id").clone());
view! {
<h1>Viewing item {id}</h1>
}
} This works exactly as expected (with the params also working as documented). Moreover, this example that didn't work whatsoever (done so because the nested view didn't work): view! {
// ...
<Route path="/item/:id/" view=ItemView/>
<Route path="/item/:id/*path" view=ItemPathView/>
// ...
} (I ended up removing the top route as the bottom route captures it, and came up with enum based routing like I did with Sauron, which worked, but really not the right way to use Leptos...) On the other hand, this works within expectations under #[component]
pub fn ItemRoutes() -> impl MatchNestedRoutes<Dom> + Clone {
view! {
<ParentRoute path=StaticSegment("item") view=|| view! { "pre" <Outlet/> "post" }>
<Route path=StaticSegment("/") view=ItemListing/>
<ParentRoute path=ParamSegment("id") view=|| view! { <Outlet/> }>
<Route path=StaticSegment("/") view=ItemView/>
<Route path=WildcardSegment("path") view=ItemPathView/>
</ParentRoute>
</ParentRoute>
}
} Having the expected route being rendered simply using more types is what I expected of a Rust project. While the whole While the This 0.7 release is shaping up to be pretty promising. |
Describe the bug
It appears the trailing slash improvements provided by #2154 and #2217 still is not quite working as one might expect.
Leptos Dependencies
I've created a fork and built the reproducible code as an example called
router_trailing_slash_axum
, so the dependency is based directly on the current main branch (or more directly, itsCargo.toml
).To Reproduce
My goal is to have the example app provide an
/item/
route that would provide a listing of all items, and individual items can be accessed using a route like/item/1/
. I had tried the following definition to take advantage of the nested routes as per documentation.What ended up happening was the route was generated as
/item
, without the trailing slash, made apparent by thedbg!
output generated by the example:As opposed to
path: "/item/"
, and that only thehttp://localhost:3000/item
route was usable, instead ofhttp://localhost:3000/item/
.I've also tried
<Route path="/item/" view=ItemTop trailing_slash=TrailingSlash::Exact>
and have the inner route be<Route path="" ...>
instead, and that actually made it worse as the/item
route no longer functioned. There are a number of other combinations I've tried but none achieved what I really wanted.Note that the
A
anchors do work as expected in this example.Expected behavior
I would have expected the route
/item/
be generated. Moreover, I wanted to use Redirect instead, but...Additional context
This might be related to the axum integration, if
Exact
is replaced with withRedirect
, duplicate routes will be generated for axum. While this is the desired behavior I do plan to have other layers be provided to axum which might be able to mitigate the redirect manually, but this failure to deal with exact trailing slashes is a complete showstopper for what I want to do (as the real application I am building has these specific routes I need working, for example,/path/target.zip
should be able to download the zip file,/path/target.zip/
should hit the application to generate a listing of the archive,/path/target.zip/dir/
might list a directory of the archive (or automatically expand the tree at that location),/path/target.zip/dir/file
might allow the download of that individual file within the archive.The text was updated successfully, but these errors were encountered: