You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to determine if a given route can be resolved within the current router context? The use case I'm running into right now is that I have an application that is transitioning from not-React to React and I want to be able to <Link> to the corresponding pages. When it's React to React, I can do this just fine, however React to not-React will break with:
No routes matched location "/<...url snip...>"
at DataRoutes (http://localhost:5173/static/node_modules/.vite/deps/react-router-dom.js?v=e0efe7f2:2662:5)
at Router (http://localhost:5173/static/node_modules/.vite/deps/chunk-DW2YRZ66.js?v=e0efe7f2:6580:15)
at RouterProvider (http://localhost:5173/static/node_modules/.vite/deps/react-router-dom.js?v=e0efe7f2:2479:5)
Is there a way to determine if a route exists in the currently active context? I could export the routes object and reference it directly but that breaks the encapsulation we have for the navigation component.
Actually, I do know the answer to this somewhat, I know this works:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Is there a way to determine if a given route can be resolved within the current router context? The use case I'm running into right now is that I have an application that is transitioning from not-React to React and I want to be able to
<Link>
to the corresponding pages. When it's React to React, I can do this just fine, however React to not-React will break with:Is there a way to determine if a route exists in the currently active context? I could export the routes object and reference it directly but that breaks the encapsulation we have for the navigation component.
Actually, I do know the answer to this somewhat, I know this works:
So I'm asking if there's a way to do this that isn't "unsafe" since the comments suggest you'd like to know about such use cases:
react-router/packages/react-router-dom/index.tsx
Line 221 in 0f2b167
Either a hook or maybe a
reloadDocumentIfNoRouteMatch
type of functionality?Beta Was this translation helpful? Give feedback.
All reactions