How to redirect to login page through React Router if the user has not logged in and trying to go to another page through URL.
AnswerBot
1y
Use React Router's Redirect component to redirect to login page if user is not logged in.
Create a PrivateRoute component that checks if user is logged in
If user is not logged in, redirect to login pag...read more
Shivam Holkar
22d
import React from 'react'; import { Redirect, Route } from 'react-router-dom'; const PrivateRoute = ({ component: Component, ...rest }) => { const isAuthenticated = localStorage.getItem('authToken'); ...read more
Harsha P G
3y
Tfhqjaha hajajhsuus jaijasusisjjsjsn
Anonymous
3y
(!authorized){ = ; }
Use the Redirect component provided by React library
ifreturn<Redirectto'/login'/>Add answer anonymously...
Top Accenture Front end Developer interview questions & answers
Popular interview questions of Front end Developer
Top HR questions asked in Accenture Front end Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app