Madhur Ahuja
Madhur Ahuja

Reputation: 22691

Maintaining browser history within same route

I have some routes within my application. There are some UI changes within a same route. For example, when I click a button, I get resources from the server and display it as a list. I want to mark this point as a separate browser history, so that when the user clicks back from any next route, I am taken back directly to the list instead of the button.

For example,

Route -A > Button is displayed

Upon click, Route A -> List is displayed

Now when item is clicked

Route B -> Item is displayed.

Now if I click back from Route B, I want to be taken back to Route A with list instead of the button. How can I achieve this?

Any ideas?

Upvotes: 0

Views: 230

Answers (1)

Grgur
Grgur

Reputation: 7382

I'll assume your app is an SPA (single page application). Routing is then just another way of maintaining application state. Therefore I see two common ways to resolve this:

  1. Create another sub-route for showing list
  2. Implement custom state management. In this case, when you go back to your route you would restore state. Many people will use Redux for global state management, but you are free to set up your own infrastructure.

Either way, you need a way to tell your view that it should render with a state different than the default.

I hope that helps.

Upvotes: 1

Related Questions