Replies: 1 comment
-
Don't navigate outside of router components. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am using React Router v7 in Data Mode. In my React components I am using a fetch wrapper to make http calls. In this fetch wrapper I have a logic that if server returns 401 then I redirect to unauthorized page. Fetch wrapper is located in a seperate file
.ts
and in this file I am using these lines to navigate:Unfortunately this breaks HMR in Vite because a circular dependency was created. The
router
object needs to access all components but components are using fetch wrapper which usesrouter
object. How to avoid this circular dependency? Is there a better way to navigate outside React components in React Router v7?Unfortunately the docs don't mention any way how to navigate outside React components -> https://reactrouter.com/start/declarative/navigating
Beta Was this translation helpful? Give feedback.
All reactions