Skip to content

Why use history.push or some other method from react-router-dom instead of just assigning the path to window.location.pathname?

It seems easier to me when I need to navigate somewhere in my code to just assign the path where I want to go to window.location.pathname. Is there any disadvantage to doing this?


Because window.location.pathname triggers a reload, defeating the entire purpose of react-router, while history.push() just changes the url and doesn’t reload. Not reloading the entire page is one of the fundamentals of a single-page-application, SPA.

Also see this: