Route Overview
Route protection means protecting any defined path from unauthorized access. For example, Signin or Signup pages are public pages and any user can access them
<AppErrorBoundary>
{generateRoutes({
isAuthenticated: isAuthenticated, // user authentication state
userRole: user.role, // user role
unAuthorizedStructure, // all the un-authentated routes goes here
authorizedStructure, // all the authentated routes goes here
anonymousStructure, // all the anonymous routes goes here
})}
<Routes>
<Route path='/' element={<Navigate to={initialUrl} />} />
</Routes>
</AppErrorBoundary>
####################
const authorizedStructure = {
fallbackPath: '/signin', // when user is not-autheticate then land here
unAuthorizedComponent: <Error403 />,// when user is autheticate but not authorized then land here
routes: [ // all authorized routed goes here
...dashBoardConfigs,
...appsConfig,
],
};
const unAuthorizedStructure = {
fallbackPath: initialUrl, // first route after login, you can change it as you want
routes: authRouteConfig,
};
const anonymousStructure = {
routes: errorPagesConfigs.concat([
{
path: '*',
element: <Navigate to='/error-pages/error-404' />,// setting 404 route
},
]),
};
Last updated