Keep React Application State in Sync with Browser History

Share this video with your friends

Send Tweet

Using pushState and passing route data via context allows our application to respond to route changes made from Link components, but using the back and forward buttons in the browser doesn’t update the application state as we would expect. In this lesson, we’ll add event handling to our Router component to handle history popState events so routing behavior is maintained for the back and forward buttons.

Elad
Elad
~ 8 years ago

Hi,

I was wondering why aren't we using react-router? - seems useful to know this package and save time implementing routers in the future.

Andy Van Slaars
Andy Van Slaars(instructor)
~ 8 years ago

Elad,

In a larger scale application, I would absolutely advise using React Router. One of the goals of this course was to avoid adding additional dependencies outside of the build setup that comes with Create React App. This was a good way to introduce topics like context and the browser's pushState API so when you use something more full featured like React Router, you have a sense of what's happening under the hood and it's less "magic".

There is a full course on React Router available here: Getting Started with React Router.

Thanks for the question and I hope this helps!