NextJS:Functions:redirect
lastmod 2023-12-01created 2023-08-193 edits
The redirect function lets you redirect the user to another URL. redirect can be used in Server Components, Client Components, Route Handlers, and Server Actions.
If you need to redirect to a 404, use the notFound function instead.
Example
import {redirect} from 'next/navigation';
export default async function RootPage() {
console.assert(false, 'Inaccessible section. Handled by middleware.');
redirect(`/your/url`);
}