Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 生产中的下一个js动态路由返回403错误,但应返回404。有什么问题吗?_Javascript_Reactjs_Nginx_Next.js_Production - Fatal编程技术网

Javascript 生产中的下一个js动态路由返回403错误,但应返回404。有什么问题吗?

Javascript 生产中的下一个js动态路由返回403错误,但应返回404。有什么问题吗?,javascript,reactjs,nginx,next.js,production,Javascript,Reactjs,Nginx,Next.js,Production,当我尝试转到https://site.con/categories/我收到403禁止,但当我转到https://site.con/categories/sport一切正常,否则路由工作正常。有什么问题吗 页面/类别/[id].js: import { categories } from '../../data/categories'; import CategoryLayout from '../../layouts/CategoryLayout'; const Page = ({ categ

当我尝试转到
https://site.con/categories/
我收到
403禁止
,但当我转到
https://site.con/categories/sport
一切正常,否则路由工作正常。有什么问题吗

页面/类别/[id].js

import { categories } from '../../data/categories';
import CategoryLayout from '../../layouts/CategoryLayout';

const Page = ({ category }) => {
  return <CategoryLayout data={category} />;
};
export async function getStaticPaths() {
  return {
    paths: Object.keys(categories).map(category => ({
      params: {
        page: category
      }
    })),
    fallback: false
  };
}

export async function getStaticProps({ params }) {
  const category = categories[params.id] || [];
  return {
    props: { category }
  };
}

export default Page;

从“../../data/categories”导入{categories};
从“../../layouts/CategoryLayout”导入CategoryLayout;
常量页=({category})=>{
返回;
};
导出异步函数getStaticPaths(){
返回{
路径:Object.keys(categories).map(categority=>({
参数:{
页码:类别
}
})),
后退:错误
};
}
导出异步函数getStaticProps({params}){
const category=类别[params.id]| |[];
返回{
道具:{category}
};
}
导出默认页面;

也面临同样的问题。看看您的服务器-您可能在/categories文件夹中没有index.html

我在这里找到了解决方案:

添加

module.exports = {
  exportTrailingSlash: true,
}
将使用index.html而不是route.html为/page中的每个路由创建物理文件夹


希望它能帮助你

面临同样的问题。看看您的服务器-您可能在/categories文件夹中没有index.html

我在这里找到了解决方案:

添加

module.exports = {
  exportTrailingSlash: true,
}
将使用index.html而不是route.html为/page中的每个路由创建物理文件夹

希望它能帮助你