DEV Community

Cover image for Creating Protected Routes With React Router V6
Atefeh  Mohammaddoust
Atefeh Mohammaddoust

Posted on

Creating Protected Routes With React Router V6

Hey, if you’re looking to find out how to create a Private Route in Reactjs, I’m going to show you how you can do it in only 2 steps. This approach is actually very clean and makes our component much simpler.

The idea is that a user must first meet certain requirements to access that route. In this case, the dashboard page can only be accessed by logged-in users

Step 1

Let’s start by creating a Component, and we call it . we can pass in more than one route inside of this component. The allows the Users component to render its child routes.

Step 2

we would simply pass in to a , and then nest all the components that we want to be private inside of this route.

that’s it 😄, Any developer who is looking forward to learning React or even the ones who have been using React for a while should be able to use and enjoy the stuff in this article!! 😄

The article has also been published in https://atefe-dev.medium.com/creating-protected-routes-with-react-router-v6-95498195128b

Top comments (0)