React Router & useHistory
In traditional websites, navigating to a new page forces the browser to completely reload. React Router allows us to swap components dynamically without a full refresh, and useHistory gives us the programmatic power to trigger these swaps.
Push vs. Replace
The history object manages a stack of URLs. history.push() adds a new entry to the top of this stack.history.replace() swaps the current URL on the stack without adding a new one. Replace is critical for login loops where you don't want the user to "back" into an unprotected login screen once authenticated.
Important Note on v6
If you are learning React Router v5, useHistory is the standard. However, in modern React Router v6+, this hook has been renamed and upgraded to useNavigate. The concepts are identical, but the syntax has been simplified!
View Full Transcript+
This section contains the full detailed transcript covering programmatic navigation, the Browser History API, and the difference between declarative (using Link tags) vs. programmatic (using history.push) navigation inside React applications.
