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
Hi! I'm currently migrating from v6.3 to v6.22.1, and would like to ask about memory router being used in the testing environment.
Since some of the code base has been migrated to use the useBlocker hook, I have to use new router API. However, it would be too much of work to migrate all existence of the previous MemoryRouter component API to the new router API.
I was thinking to wrap the new router API in a temporary small transitional component, where it calls createMemoryRouter only once when mounting the component, so that I could migrate with just a global replacement of MemoryRouter -> TemporaryMemoryRouter. Also, the code base is still relying on the Routes API.
Is there any concern with this approach? I would love to hear any comments on it.
Thank you very much for your time!
exportfunctionTemporaryMemoryRouter({
initialEntries,
initialIndex,
children =<DefaultTestPageContent/>,}: TestRouterPageProps){// Wrapping it in useState with lazy initialization to ensure it is created only onceconst[router]=useState(()=>createMemoryRouter([{path: '*',element: children,},],{
initialEntries,
initialIndex,}));return<RouterProviderrouter={router}/>;}// Sample usagetest('my test',async()=>{render(<TemporaryMemoryRouterinitialEntries={[`/my-url/`]}><Routers><Routepath="/my-url/"element={<SomePageComponent/>}/></Routes></TemporaryMemoryRouter>)// ...});
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
-
Hi! I'm currently migrating from v6.3 to v6.22.1, and would like to ask about memory router being used in the testing environment.
Since some of the code base has been migrated to use the
useBlocker
hook, I have to use new router API. However, it would be too much of work to migrate all existence of the previousMemoryRouter
component API to the new router API.I was thinking to wrap the new router API in a temporary small transitional component, where it calls
createMemoryRouter
only once when mounting the component, so that I could migrate with just a global replacement ofMemoryRouter
->TemporaryMemoryRouter
. Also, the code base is still relying on theRoutes
API.Is there any concern with this approach? I would love to hear any comments on it.
Thank you very much for your time!
Beta Was this translation helpful? Give feedback.
All reactions