Redirect and notFound
To perform a redirect or render the not‑found page, use the built‑in Next.js functions from next/navigation.
import { redirect, notFound } from 'next/navigation';
export default class UserController {
@get('redirect')
static async redirect() {
// ... if something
redirect('/some-other-endpoint');
}
@get('not-found')
static async notFound() {
// ... if something
notFound();
}
}Both functions work by throwing an error, so you don’t need a return statement. TypeScript casts their return type as never.
See the Next.js documentation for more information.
Last updated on