T
TanStack•2mo ago
like-gold

Initial entries in browser history

Is it possible/feasible to allow initialEntries in the createBrowserHistory function params? Same thing that already exists in createMemoryHistory. My use case is that we rely on useCanGoBack to display back buttons inside of the application, but a page reload causes the router to lose its internal history stack. I was wondering if I could create my own history tracker stored in sessionStorage that would populate the initialEntries, but it's not supported as an option right now.
5 Replies
quickest-silver
quickest-silver•2mo ago
no this does not work browser history is using.... the browser history 🙂 this does not offer the API to put stuff there instead of the useCanGoBack hook we have long planned to record all history actions in sessionStorage and expose this an addon to history if you want to contribute to this, you are more than welcome!
like-gold
like-goldOP•2mo ago
nice to hear you have it on your radar, do you have any reference/issue about it yet?
quickest-silver
quickest-silver•2mo ago
nothing written down i think cc @ferretwithabéret
eastern-cyan
eastern-cyan•2mo ago
Yeah, I did not have much time lately, personal stuff and many work projects. This mostly has to do with the history API of tanstack router. You'd want to make some sort of wrapper function, middleware system or a new custom history to handle this. If you want to contribute, just read through the CONTRIBUTING.md file, and if you need help, likely you can ask here. You can also open the PR while you are still working on it, so others can jump in and come up with ideas IMO the tanstack history API needs some refactoring, and I thought once about making every navigation go through 1 single place (ideally tryNavigation). At the moment, for the browser history, there are multiple places where navigation logic is handled: - tryNavigation for push/replace; - onPushPopEvent for back/forward/go; - onBeforeUnload for when you go back/forward outside of the current app (i.e. you go to a completely different website). My fix for this would've been to, instead, set some flags before calling tryNavigation, e.g. isPushPop, isBeforeUnload. And then the whole handling would be managed by tryNavigation.
quickest-silver
quickest-silver•2mo ago
yes the refactoring sounds like something we should do before adding more stuff

Did you find this page helpful?