RequireAuth¶
Import¶
Function Signature¶
RequireAuth({fallbackPath: string}
): React.ReactNode
RequireAuth provides a solution for implementing auth on per per-component basis for private route solutions using the react-router-dom route system
Parameters¶
Name | Type | Description |
---|---|---|
fallbackPath |
string |
Path to redirect if the user is not authenticated |
Example¶
const RoutesComponent = () => {
return (
<BrowserRouter>
<Routes>
<Route path={'/'} element={<Home/>}/>
<Route path={'/login' } element={<Login/>}/>
<Route path={'/secure'} element={
<RequireAuth fallbackPath={'/login'}>
<SecureComponent/>
</RequireAuth>
}/>
</Routes>
</BrowserRouter>
)
}
Defined in¶
packages/react-router/src/RequireAuth.tsx
— 🔑 —
React Auth Kit is MIT License code