Routing: Routing plays an important role.
Protected Routes: Bad :
<Route path="/dashboard" element={ isAuthenticated ? <Dashboard / > : <Login />}>
Note: it displays the Login screen but the URL path is Dashboard and repeats the same process for all pages. Suppose you have 30 pages then you need to write for every page.
Good: Extract the authentication logic into a wrapper.
const ProtectedRoutes({children})=>{
//write auth logic here...
let isAuthenticated=false;
return isAuthenticated? <Outlet /> : <navigate to="/login" />
}
Note: Outlet is the children.
Routes : Single protected Route:
<Route element={<ProtectedRoute />} >
<Route path="/about" element={<Dashboard />} />
<Route>