Skip to content

Use redirect from "next/navigation" to perform a relative redirect#54

Open
CoocooFroggy wants to merge 1 commit into
mainfrom
next-navigation-redirect
Open

Use redirect from "next/navigation" to perform a relative redirect#54
CoocooFroggy wants to merge 1 commit into
mainfrom
next-navigation-redirect

Conversation

@CoocooFroggy
Copy link
Copy Markdown

With NextResponse.redirect() from next/server, we are forced to use an absolute URL for this HTTP redirect; you have to work with the reverse proxy Coolify / Nixpacks uses to find your public URL to build that absolute path.

By using redirect() from next/navigation, we are allowed to specify relative redirects instead. Initially I thought it might just be a frontend function, but it seems intended to be used in the back end as well:

The redirect function allows you to redirect the user to another URL. redirect can be used while rendering in Server and Client Components, Route Handlers, and Server Functions.

https://nextjs.org/docs/app/api-reference/functions/redirect

Location header is thus Location: /student/dashboard or whatever else you need! Rather than Location: http://localhost:3000/student/dashboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant