atlassian-labs / react-resource-router

Configuration driven routing solution for React SPAs that manages route matching, data fetching and progressive rendering
https://atlassian-labs.github.io/react-resource-router
Apache License 2.0
202 stars 28 forks source link

History stack introspection #166

Closed anacierdem closed 2 years ago

anacierdem commented 2 years ago

I think a router library should provide a mechanism to track the route history. Latest react-router have the useLocation hook to listen for route changes, which you can then push onto a stack if you like.

Either, we should have a mechanism to inspect the current history stack (no need for write access - just inspection) or a similar hook to listen for all route changes.

The ability to listen to changes is not very useful for implementing breadcrumbs for example so inspecting the history is the better API in my opinion.

Is there a practical way of listening to all route changes or preferably inspecting history with the current API?

anacierdem commented 2 years ago

Ok there is already RouteSubscriber to listen to route changes.

albertogasparin commented 2 years ago

Even better we provide a createRouterSelector that allows you to create hooks that re-render only when specific parts of the router state change (like location). So you can easily build your own, optimised useLocation hook