Home > database >  NextJS Dynamic Routes error 404 in production
NextJS Dynamic Routes error 404 in production

Time:01-14

In my next.js project, I have one dynamic routes page for the project. I don't fetch projects at all. Instead of that I just import a local JSON file with data. It works fine on the development side, but in production, for every page, I just take error 404 for the not existing page.

Because my website is whole static in production it is static, can it maybe be a problem? What are my solutions to this problem?

import React from "react";

import { projects } from "./../projects/content";

const Project = (props) => {
  const project = props?.project;

  if (!project) return null;

  return (
   // some code
  );
};

export default Project;

export async function getStaticProps({ params }) {
  const project = projects[params.project.toLowerCase()];

  if (!project) {
    return { notFound: true };
  }

  return {
    props: { project: project },
  };
}

export async function getStaticPaths(context) {
  return {
    paths: [],
    fallback: "blocking",
  };
}

CodePudding user response:

export async function getStaticPaths(context) { return { paths: [{ params: { id: '1' } }, { params: { id: '2' } }], fallback: "blocking", }; }

You will need to pass the path since your fallback is blocking.

  • Related