S
SolidJS11mo ago
sponge

useNavigate wrapped in <Router>

Hello! I'm trying to use useNavigate inside a top-level element so I can setup some event listeners that will trigger navigations app-wide: https://playground.solidjs.com/anonymous/2ea655b2-d438-4ead-ac5d-a6f134d79e26 gives me Uncaught Error: Make sure your app is wrapped in a <Router /> Several Stack Overflow answers said that you can't use useNavigate inside an event listener, which is what I was originally doing, so I tried to move it into a new component that is nested underneath <Router> but it seems like useNavigate only works on a component inside <Route>. Is this intentional behavior, despite the error message looking for <Router>? Is there any other way to instantiate useNavigate at a high enough level that it will always trigger regardless of the current route? Thank you!
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
4 Replies
Brendonovich
Brendonovich11mo ago
GitHub
GitHub - solidjs/solid-router: A universal router for Solid inspire...
A universal router for Solid inspired by Ember and React Router - GitHub - solidjs/solid-router: A universal router for Solid inspired by Ember and React Router
sponge
spongeOP11mo ago
ah ok, so in that case, useNavigate can go inside App?
Brendonovich
Brendonovich11mo ago
yep
sponge
spongeOP11mo ago
ah that did it, saw that in the docs but didn't realize how it applied to me. thank you!
Want results from more Discord servers?
Add your server