From the course: Building Production-Ready React Apps: Setup to Deployment with Firebase
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Use the React router hooks: useNavigate
From the course: Building Production-Ready React Apps: Setup to Deployment with Firebase
Use the React router hooks: useNavigate
- [Instructor] React Router offers a few useful hooks that you can use in your React applications to perform navigation tasks. First, you have useParams, that returns an object of key/value pairs of the dynamic params from the current URL that matches the route path. Then you have useNavigate, that returns a function that lets you navigate programmatically to another view. Finally, you have useLocation, that returns the current location object. And this can be very useful if you'd like to perform some side effects whenever the current location changes. For the next example, we're going to use useNavigate and useLocation. Basically what we want is to allow the user to navigate to another view to display one image individually. So let's go back to the source code. So, first, we're going to go to Card. And I'm going to add to this code this useNavigate. That's going to be from react-router-dom also. So we're going to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
-
(Locked)
Install React router DOM v62m 53s
-
(Locked)
Configure the routes and create a navigation component2m 51s
-
(Locked)
Use Link component to navigate between pages4m 58s
-
(Locked)
Allow navigation between multiple views5m 39s
-
(Locked)
Conditional rendering and protected route4m 45s
-
(Locked)
Use the React router hooks: useNavigate4m 58s
-
(Locked)
Use the React router hooks: useLocation4m 35s
-
(Locked)
Create the routes for "NotFound" and "Profile"5m 15s
-
(Locked)
Display the active link3m 42s
-
(Locked)
-
-
-