Why Does The React Router History Length Increase On Refresh?
The first time I open the app, the length of the history object (returned by the useHistory Hook) is 3.
On every further refresh, the length gets incremented. Why is that? Does this happen in production too?
Environment:
Answer
If you navigate to the site in a tab where you have been visiting other pages, history.length will be >1. history.length is the number of locations in the joint session history, not the current site's session history.
Even opening a new tab and entering the url of your app will mean a history.length of 2: blank tab + your url. You can get a length of 1 if you arrive directly at the page through a link on a new window/tab.
This may explain >1 length when first opening your app. This doesn't answer why your app increases the length on refresh, so it may have to do with your specific structure.
Related Questions
- → Import statement and Babel
- → should I choose reactjs+f7 or f7+vue.js?
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → .tsx webpack compile fails: Unexpected token <
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → React Native with visual studio 2015 IDE
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
- → How do I determine if a new ReactJS session and/or Browser session has started?
- → Alt @decorators in React-Native
- → How to dynamically add class to parent div of focused input field?