This video is available to students only

Installing React Router

In this lesson, we're going to install React Router

Installing React Router to our project#

Since we're preparing skeleton for our React project, it's very important to add routing. For that, we're going to use the very popular React Router. React Router is tried and tested, so we don't have to look around for any other alternative to this. This is basically a collection of navigational components which help render components at different routes. As we know, components are building blocks of any React application. This is exactly based on that.

Since we're building a web application, we can simply click on web; and as you can see, it's as straightforward as it could be. If we scroll down a bit, and look at the API option, we have the hooks section. Out of these four, I'm pretty sure we'll be using the useLocation, useParams & useHistory hook. We also have a Browser Router, which is basically a wrapper around our routes. We also have links, which work as an anchor tag in JSX; they redirect you to another page without refreshing it. There is also Navlink, which is very similar to Links but the additional feature is that you can add styling to the links here. For example, you'll be able to highlight the current link where the user is currently.

We can now simply install it by opening the terminal. Make sure you're inside the client project. Now type

Start a new discussion. All notification go to the author.