Choosing which component to render in the handler #503
-
I would like to choose which component to display in a handler based on some conditions. For example, if a user is authenticated, I would like to render my app page, otherwise I want to render the landing page with a login form. But I only have access to |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You can render route component with custom props. Here is a snippet for example:
|
Beta Was this translation helpful? Give feedback.
-
This has become a lot easier with Async route components: export default async function MyPage(req: Request, ctx: RouteContext) {
const isLoggedIn = await checkUserAuth(req);
if (!isLoggedIn) {
return <p>not logged in</p>
}
return <p>logged in</p>
} |
Beta Was this translation helpful? Give feedback.
This has become a lot easier with Async route components: