#Save and load Memory Router state in a cookie

1 messages · Page 1 of 1 (latest)

remote coral
#

I have an embedded app. It sits on customer's websites (think a live chat widget), with several routes. I'd like to use reactRouter's memory router because it works perfectly for our scenario. However I also need it to save the state on refresh. What I'm looking to do is save some sort of cookie react-router-history: string[] and react-router-index: number which represents the current history and can be loaded in as initial state. Has anybody done anything similar or know how this might be achieved?

left valley
#

This approach ensures that the router’s state is persisted across page refreshes, providing a seamless experience for users interacting with your embedded app. The key is to intercept and save the history state on every navigation and restore it when the app initializes.

remote coral
#

@left valley can you demonstrate how you intercept and save the history state on every navigation?