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
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 uses router object. How to avoid this circular dependency? Is there a better way to navigate outside React components in React Router v7?
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
-
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