Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing history #779

Open
marcospassos opened this issue Jan 5, 2021 · 5 comments
Open

Accessing history #779

marcospassos opened this issue Jan 5, 2021 · 5 comments

Comments

@marcospassos
Copy link

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?

@taion
Copy link
Contributor

taion commented Jan 5, 2021

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().

@marcospassos
Copy link
Author

marcospassos commented Jan 5, 2021

Where do you store the index? Do you register an listener for route changes?

@taion
Copy link
Contributor

taion commented Jan 5, 2021

Store in location.state when "leaving" the old category.

@marcospassos
Copy link
Author

But is there a way to listen to route changes in order to add this information to the location state?

@marcospassos
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants