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

Router fails to navigate if wrapping view is missing #590

Open
valeth opened this issue Mar 19, 2023 · 0 comments
Open

Router fails to navigate if wrapping view is missing #590

valeth opened this issue Mar 19, 2023 · 0 comments
Labels
A-ergonomics Area: API ergonomics A-router Area: router

Comments

@valeth
Copy link

valeth commented Mar 19, 2023

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

  • Sycamore: master
  • Browser: Firefox 111
@lukechu10 lukechu10 added A-ergonomics Area: API ergonomics A-router Area: router labels Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ergonomics Area: API ergonomics A-router Area: router
Projects
None yet
Development

No branches or pull requests

2 participants