Next.js Discord

Discord Forum

Route Groups

Answered
Silver carp posted this in #help-forum
Open in Discord
Silver carpOP
Guys, one question

When I have a folder

/idea-management

And inside this folder there is a layout.tsx and two route groups (ideator) with its page.tsx and (manager) with its page.tsx, I wanted to know how to redirect to the correct route group according to a condition
Answered by James4u
yeah, so route group is for grouping multiple routes without any additional route segment - also when you want to apply the same layout to them
View full answer

24 Replies

Hmm what do you mean by redirect to the route group? not a specific route?
Silver carpOP
I don't think redirect would work, because route group doesn't affect the url
Maybe in the layout I could do the validation? And then call the correct component?
that's what I would like to ask, you only have page.tsx inside ideator and manager
why do you use route group then?
Silver carpOP
Because they are different views, according to the user's role
And maybe I need to implement components for the route group, so I thought about putting a components folder in its respective group
use /idea-management/ideator and /idea-management/manager then
for those two different user role
Silver carpOP
I can't modify the url with ideator and manager
it has to be /idea-management
I see, but route group is not for this @Silver carp
what you can do is just have a single page.tsx in /idea-management
and then you can check user role there right?
and then have two components (not pages) and return one of them depending on the user role
you can think as of a simple conditional rendering
@James4u use `/idea-management/ideator` and `/idea-management/manager` then
if you don't want different routes for different user role, conditional rendering is only the way - not route group
Silver carpOP
I see, thank you, I'll continue like this then!
route groups wouldn't work in this scenario, right?
yeah, so route group is for grouping multiple routes without any additional route segment - also when you want to apply the same layout to them
Answer
it won't work in your case
Silver carpOP
I see, in this case the route group (app) made sense because they have the same layout, with menu and header
Thanks @James4u