Skip to content
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

Path Params not begin passed to nested routes in 0.7 #2719

Closed
osmano807 opened this issue Jul 26, 2024 · 1 comment
Closed

Path Params not begin passed to nested routes in 0.7 #2719

osmano807 opened this issue Jul 26, 2024 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@osmano807
Copy link

Describe the bug
Path params are passed to the ParentRoute but not the the nested Route. In 0.6 I use this nested routes to implement sidebar/drawers.

Leptos Dependencies
Actually running 4bc999e

leptos = { git = "https://github.com/leptos-rs/leptos.git", branch = "leptos_0.7" }
leptos_axum = { git = "https://github.com/leptos-rs/leptos.git", branch = "leptos_0.7" }
leptos_meta = { git = "https://github.com/leptos-rs/leptos.git", branch = "leptos_0.7" }
leptos_router = { git = "https://github.com/leptos-rs/leptos.git", branch = "leptos_0.7" }

To Reproduce

#[component]
pub fn App() -> impl IntoView {
    provide_meta_context();

    view! {
        <Router>
                <Routes fallback=|| { view!{}  }>
                    <ParentRoute path=path!("/test/:test_id") view=TestParent>
                        <Route path=path!("") view=TestChild />
                    </ParentRoute>
                </Routes>
         </Router>
    }
}

#[component]
fn TestParent() -> impl IntoView {
    let params = leptos_router::hooks::use_params_map();

    tracing::info!("TestParent Params: {:?}", params.get());

    view! { <Outlet /> }
}

#[component]
fn TestChild() -> impl IntoView {
    let params = leptos_router::hooks::use_params_map();

    tracing::info!("TestChild Params: {:?}", params.get());

    view! { <p>Child</p> }
}

Expected behavior
Should get the :test_id param in both the ParentRoute and child Route, instead I get:

INFO request:call: app/src/lib.rs:264: TestParent Params: ParamsMap([("test_id", "my_id")]) method=GET uri=/test/my_id version=HTTP/1.1
INFO request:call: app/src/lib.rs:273: TestChild Params: ParamsMap([]) method=GET uri=/test/my_id version=HTTP/1.1
@gbj
Copy link
Collaborator

gbj commented Jul 27, 2024

Oh interesting, I hadn't noticed that this is now backwards: putting the param in the child gives it to both of them.

#[component]
pub fn App() -> impl IntoView {
    provide_meta_context();

    view! {
        <Router>
            <Routes fallback=|| ()>
                <ParentRoute path=path!("/test") view=TestParent>
                    <Route path=path!(":test_id") view=TestChild/>
                </ParentRoute>
            </Routes>
        </Router>
    }
}
TestParent Params: ParamsMap([("test_id", "foo")])
TestChild Params: ParamsMap([("test_id", "foo")])

Will fix. Honestly though maybe just providing all the matched params to routes at every level makes the most sense. This has been raised a couple times and is reasonable enough.

@gbj gbj added this to the 0.7 milestone Aug 2, 2024
@gbj gbj added the bug Something isn't working label Aug 8, 2024
@gbj gbj closed this as completed in 0222182 Aug 11, 2024
chrisp60 pushed a commit to chrisp60/leptos that referenced this issue Aug 12, 2024
chrisp60 pushed a commit to chrisp60/leptos that referenced this issue Aug 12, 2024
chrisp60 pushed a commit to chrisp60/leptos that referenced this issue Aug 12, 2024
chrisp60 pushed a commit to chrisp60/leptos that referenced this issue Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants