dark
dark copied to clipboard
[web-router] protected routes, how to implement them?
Web router expects factory functions in the component
field, which means I cannot do
// ./routes.jsx
import AuthProvider from './components/AuthProvider'
const Dashboard = lazy(() => import('./pages/Dashboard'))
export const routes = [
{
path: '/',
component: Root,
children: [
{
path: '',
component: <AuthProvider><Dashboard /></AuthProvider>
},
{
path: 'login',
component: lazy(() => import('./pages/Login'))
},
{
path: 'not-found',
component: lazy(() => import('./pages/NotFound'))
},
{
path: '**',
redirectTo: 'not-found'
}
]
}
]
I also cannot do
// ./pages/Dashboard.jsx
export default AuthProvider(Dashboard)
How does one implement "protected routes" with web-router?