Next.js Discord

Discord Forum

Rewrites from Route Handlers

Unanswered
Africanized honey bee posted this in #help-forum
Open in Discord
Africanized honey beeOP
Just tried to create a route in app directory at the index / with the intention to rewrite it to one of three different possible pages after a database call on the server. Got a message that Error: NextResponse.rewrite() was used in a app route handler, this is not currently supported. Please remove the invocation to continue. Is this something that will be supported eventually, or is there a better way to approach this pattern?

2 Replies

I think it's expected to use redirect from next/navigation for redirects outside of middleware.
https://nextjs.org/docs/app/api-reference/functions/redirect#example
@Marchy I think it's expected to use `redirect` from `next/navigation` for redirects outside of middleware. https://nextjs.org/docs/app/api-reference/functions/redirect#example
Africanized honey beeOP
Thanks for responding! I'm specifically looking for a way to rewrite as opposed to completely redirect the request. Redirecting doesn't seem to be an issue. Goal is to show the user the index path / even though I might want to rewrite User A to /foo and User B to /bar.