Home > other >  How to prevent Vercel routing to not finding the page
How to prevent Vercel routing to not finding the page

Time:12-30

I am building a project using NextJs and Vercel, but, when the users try to access a new page or route, the Vercel gives them the 404 error.

In other projects, I used Netlify as router and this error was fixed using the netlify.toml config file, but, I am not able to do the same using the vercel.json file.

Can you guys help me to turn this file:

netlify.toml

[[redirects]]
from = "/*"
to = "/index.html"
status = 200

Into a vercel.json config file?

I was trying with this settings: vercel.json

{
    "rewrites": [{ "source": "/(.*)", "destination": "/index.html"}]
}

But it did not solved my issue.

CodePudding user response:

A workaround is to use a catch all route that immediately redirects to the index page. For example:

// [...404].jsx

export default function Page() {
  return null;
}

export function getServerSideProps() {
  return {
    redirect: {
      destination: '/',
      permanent: false,
    },
  };
}
  • Related