sycamore-rs / sycamore

A library for creating reactive web apps in Rust and WebAssembly
https://sycamore-rs.netlify.app
MIT License
2.79k stars 148 forks source link

Router fails to navigate if wrapping view is missing #590

Open valeth opened 1 year ago

valeth commented 1 year ago

Describe the bug If a router is created like this...

view! { ctx,
    Router(
        integration = HistoryIntegration::new(),
        view = |ctx, route: &ReadSignal<AppRoutes>| {
            match route.get().as_ref() {
                AppRoutes::Index => Index(ctx),
                AppRoutes::Login => Login(ctx),
                AppRoutes::NotFound => view! { ctx, "Not found" },
           }
    })
}

...then it is unable to navigate back if you are for example on the Login page. The URL in the address bar is still being updated, but I assume it cannot track the view. Wrapping the match statement in a view, like it is shown in the book, properly tracks the router again.

While this is shown in the book example it is still quite error prone. One way this might be fixed is by making Router always wrap its closure in an implicit view. Unless there's some restriction with the reactive system that I'm not aware of.

To Reproduce

  1. Create an app with a router like in the code snippet above.
  2. Attempt to navigate by using the navigate() function.
  3. Get stuck on the current rendered component.

Expected behavior Navigate to the url when using navigate().

Environment