found
found copied to clipboard
Accessing history
We have an area where we want to include a button that navigates the users back to the previous context. The context here is not the page immediately before, but another area.
How is the best way to approach this use case? Is there any way to associate metadata (such as the context name related to a route) to the history and access them later?
In general, we delegate to the browser to do all the history tracking, and don't try to do duplicate tracking of history states (because that might go out-of-sync/wrong).
For similar use cases, one approach might be to store the index of the most recent location with the previous context, then calculating "stored index - current index" to figure out the delta for .go().
Where do you store the index? Do you register an listener for route changes?
Store in location.state when "leaving" the old category.
But is there a way to listen to route changes in order to add this information to the location state?
I'm asking because there isn't a single link to leave an area. It looks like I need somehow inject the state from the routing layer based on the route itself.