Skip to content

Redirect 404 errors #13813

Answered by jaybytez
jaybytez asked this question in Help
Discussion options

You must be logged in to vote

I was able to solve this by using the latest canary version as well as the experimental feature but instead of rewrites, using redirects:

experimental: {
    redirects() {
      return [{ source: '/error404', destination: 'http://www.sample.com/404.html', permanent: true }];
    },
  },
};

Then I created the _error.js to do a router push to /error404 based on the sample code from the docs and a few of the comments for doing the redirect.

import { useEffect } from 'react';
import { useRouter } from 'next/router';

function Error({ statusCode }) {
  console.log('Error - Error Component');
  const router = useRouter();
  useEffect(() => {
    router.push(`/error404`);
  });
  return '';
}

E…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jaybytez
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant