#NextJS redirect
1 messages · Page 1 of 1 (latest)
Hi @high flame. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
In Next.js, you can use the redirect function from 'next/navigation' to redirect to another page. Here's an example of how you can use it:
import { redirect } from 'next/navigation'
export default async function Profile({ params }) {
// ... your code here ...
// If a certain condition is met, redirect to another page
if (!condition) {
redirect('/login')
}
// ... your code here ...
}
In this example, if the condition is not met, the user will be redirected to the '/login' page. Note that redirect does not require you to use return redirect() as it uses the TypeScript never type.
You can find more information about this in the Next.js documentation (https://nextjs.org/docs/app/api-reference/functions/redirect).
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@zinc saddle kapa.ai is still learning and improving, please let us know how it did by reacting below