Neha / AMA

AMA - Ask me anything
10 stars 2 forks source link

Protecting Routes in React #7

Open jainpawan21 opened 5 years ago

jainpawan21 commented 5 years ago

How to protect routes in react.js? I want to protect whole react-app routes unless user either register or login in the app and after then user can't access that register and login routes but can access other routes?

Neha commented 5 years ago

You can do route authentication by using HOC in React-Router. Below could be helpful for you. This is the official example by the React Router team.

https://reacttraining.com/react-router/web/example/auth-workflow

Thanks, Neha

jainpawan21 commented 5 years ago

Thanks Mam