SolidJSS
SolidJSโ€ข2y agoโ€ข
4 replies
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!
Quickly discover what the solid compiler will generate from your JSX template
Was this page helpful?