课程: Learning Full-Stack JavaScript Development: MongoDB, Node, and React

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Handling browser navigation history

Handling browser navigation history

- [Instructor] When we go to the page for a single contest right now, we just change the state of the application to render that, but we have not changed the URL. Ideally, every contest should get its own URL so that we can share this contest with others. To do that in a single page application, we will have to use the history API, this is not something supported by React, there is no React API to manipulate the history API, but there are libraries out there like React Router that wraps the history API and provides its own API for us to use. But for this course, I'm going to use the native DOM history API, I think it's simple enough for us to use, and I think it's important to understand the core client routing using the native history API. So on the window object in every browser there is a history class, and it has a few functions, the one we need to change a URL of page is pushState, and as you can see from Chrome,…

内容