Say we have Home, Page A, Page B and Page C. If I do this:
- Open Page B
- Go Home
- Go to Page B
This pushes at least 3 routes in the history object. If I repeat the steps, there will be 6 items. This is true when pushing directly via history.push
and also when using the Link component's with the to
prop.
The only way to keep complexity under control is by checking the previous location and then doing either history.goBack
or history.push
: Check history previous location before goBack().
The catch is that managing the history
object can become a very complicated task very quickly. Just by adding a navigation bar that is rendered on every page in the app, you add at least "n-1" places from where you can go back home (assuming home is one of the navigation tabs).
Should we be concerned about this and handle the previous location?
Possibly related question: Why does the React Router history length increase on refresh?
Environment:
- history is BrowserHistory
- [email protected]
- [email protected]
history
object is meant to hold the list of pages the user previously visited. If the user visited the same page more than once why shouldn't that page appear in the list more than once? – Elan Hamburgerhistory.goBack
to navigate backward. – Paul Razvan Berghistory
is supposed to mimic browser history. If you go to page A, click a link to page B, click a link to page A, and click the back button twice, you should end up at page A again. – Elan Hamburger