App Router with same component viewed differently
Answered
Router Renegade posted this in #help-forum
So, in Next js App router, how can i display the same page in a different manner for different users? is it possible to achieve this?
or in other words, I want to display the
or in other words, I want to display the
Home component of my app, in a different manner for 3 different types of users [owner, admin and user]Answered by B33fb0n3
you can do this by checking the specific type of the user and render different components of it:
That would be an easy way to implement different dashboards for different types of user
const userType = "user" // can be owner, admin, user
switch(userType) {
case "user":
return <UserDashboard />
case "owner":
return <OwnerDashboard />
case "admin":
return <AdminDashboard />
}That would be an easy way to implement different dashboards for different types of user
12 Replies
@Router Renegade So, in Next js App router, how can i display the same page in a different manner for different users? is it possible to achieve this?
or in other words, I want to display the `Home` component of my app, in a different manner for 3 different types of users [owner, admin and `user`]
you can do this by checking the specific type of the user and render different components of it:
That would be an easy way to implement different dashboards for different types of user
const userType = "user" // can be owner, admin, user
switch(userType) {
case "user":
return <UserDashboard />
case "owner":
return <OwnerDashboard />
case "admin":
return <AdminDashboard />
}That would be an easy way to implement different dashboards for different types of user
Answer
happy to help
Barbary Lion
@Router Renegade
You might wanna use [parallel routes](https://nextjs.org/docs/app/building-your-application/routing/parallel-routes) for this. Depending on the user type, they can even go to different routes. Here's an example:
You might wanna use [parallel routes](https://nextjs.org/docs/app/building-your-application/routing/parallel-routes) for this. Depending on the user type, they can even go to different routes. Here's an example:
export async function Layout({user, owner, admin}: {
user: React.ReactNode
owner: React.ReactNode
admin: React.ReactNode
}) {
// You would dynamically retrieve this from cookie-based sessions or similar methods
const userType = await getUserType();
if (userType === "admin") return admin;
else if (userType === "owner") return owner;
else return user;
}thank u
I will check
I am using App router tho
@Router Renegade I am using App router tho
Barbary Lion
It actually works with App router.
