Skip to content


    The redirect function allows you to redirect the user to another URL. If you need to redirect to a 404, you can use the notFound function.


    Invoking the redirect() function throws a NEXT_REDIRECT error and terminates rendering of the route segment in which it was thrown. redirect() can be called with a relative or an absolute URL.

    import { redirect } from 'next/navigation';
    async function fetchTeam(id) {
      const res = await fetch('https://...');
      if (!res.ok) return undefined;
      return res.json();
    export default async function Profile({ params }) {
      const team = await fetchTeam(;
      if (!team) {
      // ...

    Note: redirect() does not require you to use return redirect() due to using the TypeScript never type.

    Was this helpful?