From the course: Building Production-Ready React Apps: Setup to Deployment with Firebase
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Display the active link
From the course: Building Production-Ready React Apps: Setup to Deployment with Firebase
Display the active link
- [Instructor] Now we can navigate between the multiple views of our single-page application. What would be nice also is to actually display which link is active. So when you are in this location, showing which link is active based on the current pathname. So, we're going to go back to this components Navbar and find the navigation. So this is where you have all the links. And just make sure that you have, here at the top, we're going to add this hook from the react-router library, useLocation. This one returns an object. And in this object, we're going to get the information of the pathname in order to give us the current location. And here we've been using for every link the same class, CSS, in order to display an active link. So actually, let's remove this one from the second link. You're going to see the difference. And here you can see that this one is slightly faint and this one is darker. So this is to display…
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)
-
-
-