Conditional rendering routes #8615
Unanswered
szilagyi-sandor
asked this question in
Q&A
Replies: 1 comment
-
What I normally do is setup 2 different routers, one for authenticated users, one for visitors. function AppRouter() {
const { user } = useAuth();
if (user.isLoggedIn) {
return (
<BrowserRouter>
<Switch>
<Route exact path='/' component={UserHome} />
<Route path='/profile' component={UserProfile} />
...
</Switch>
</BrowserRouter>
)
}
return (
<BrowserRouter>
<Switch>
<Route path='/login' component={LoginPage} />
<Route path='/signup' component={SignUpPage} />
<Route path='/forgot' component={ForgotPasswordPage} />
</Switch>
</BrowserRouter>
)
} The |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is it ok to conditional render routes? I want to achieve a different layout with different routes to logged in users and visitors.
Beta Was this translation helpful? Give feedback.
All reactions