DEV Community


Posted on

Creating a Protected Route in React

You can make a page private in React Router by creating a protected route. This protected route can be used as a wrapper around route element you want to be private. Authorization will grant the user access to the private route. In this example we create a context, which holds the current authenticated state. Clicking the login button will set authenticated to true and then the user has access to the private page.

Top comments (0)