Next.js Discord

Discord Forum

How to redirect to subpage?

Unanswered
Maine Coon posted this in #help-forum
Open in Discord
Maine CoonOP
If a user goes to the /user-management path, I want it to immediately redirect to /user-management/manage-users

I tried redirect("/add-new-user") inside my layout.tsx but that prevents me from being able to return JSX content (I need it so I can put a submenu)

Structure:
/app/user-management/layout.tsx
/app/user-management/add-new-user/page.tsx
/app/user-management/manage-users/page.tsx

2 Replies

Mugimaki Flycatcher
Create a route.ts file and handle your logic. Don't know if this is the bes approach.

For example what I did with profile route, basePath/profile should nagivate to basePath/profile/slug if user is logged. Else I navigate to login.
Plott Hound
Put the redirect in user-management/page.tsx