I am trying to understand the difference between BrowserRouter
and Router
of the react-router-dom
(v5) package and what difference it
You can access history via the useHistory hook let history = useHistory();
to perform history.push()
for BrowserRouter.
Looking at the HTML5 History API documentation, it seems that the history API preserves state for the user automatically. Say you are at page 1 initially and page 1 has a page outlook A. You performed some actions that changes the page 1 outlook to B. If you now moves to page 2, when you click the back button on the browser, you will be direct back to page 1. History API preseves your state so it knows to render outlook B to you, so that is the advantage of using This is not true. I am not sure about the difference.BrowserRouter
. Though I am not 100% sure, I suppose Browser
doesn't come with this functionality and in which case it will render outlook A when you get directed back to page 1.
BrowserRouter
ignores the history prop as it handles the history automatically for you. If you need access to the history outside of a react component, then using Router
should be fine.