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
Hello, hope you are well! Thanks for the library its been great
My team is using react-router@v6 for a Chrome extension, specifically for the pop-up script. We are using the createMemoryRouter function to create an in-memory router, as our extension can't use the normal browser URL navigation, same as any native application (e.g. React Native)
This allows us to have separate routes / pages in our extension, within that little pop-up window, and we have a custom back button that calls the new navigate(-1) API to navigate backwards manually
However we have a problem: we can't hide or disable the back button if there is nowhere to go back to because the in-memory history state is not exposed. Ideally we would be able to access the in-memory history for our router and check if the length is > 1, then allow going backwards, otherwise hide the button
I tried to workaround by using the UNSAFE_DataRouterContext, via property router.window.history.length, but this length seems to always be 1. Perhaps it is a bug with navigating to the current route again (e.g. for page/:id our app can go from /page/1 to /page/2) or perhaps there is a bug in the in-memory implementation? Or maybe this is not the wrong way to access this info?
I looked through the source code, and noticed the MemoryHistory interface exposes an index() getter, and also perhaps a length, so I was hoping that could somehow be exposed for us to use, so we can hide the back button
Let me know if you need a more concrete example or some sample code, thanks for the consideration
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
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, hope you are well! Thanks for the library its been great
My team is using
react-router@v6for a Chrome extension, specifically for the pop-up script. We are using thecreateMemoryRouterfunction to create an in-memory router, as our extension can't use the normal browser URL navigation, same as any native application (e.g. React Native)This allows us to have separate routes / pages in our extension, within that little pop-up window, and we have a custom back button that calls the new
navigate(-1)API to navigate backwards manuallyHowever we have a problem: we can't hide or disable the back button if there is nowhere to go back to because the in-memory history state is not exposed. Ideally we would be able to access the in-memory history for our router and check if the length is > 1, then allow going backwards, otherwise hide the button
I tried to workaround by using the
UNSAFE_DataRouterContext, via propertyrouter.window.history.length, but this length seems to always be1. Perhaps it is a bug with navigating to the current route again (e.g. forpage/:idour app can go from/page/1to/page/2) or perhaps there is a bug in the in-memory implementation? Or maybe this is not the wrong way to access this info?I looked through the source code, and noticed the
MemoryHistoryinterface exposes anindex()getter, and also perhaps alength, so I was hoping that could somehow be exposed for us to use, so we can hide the back buttonLet me know if you need a more concrete example or some sample code, thanks for the consideration
Beta Was this translation helpful? Give feedback.
All reactions