繁体   English   中英

Next.js 加载主页而不是 404 页面

[英]Next.js loads homepage instead of the 404 page

我有一个带有自定义 404 页面的 Next.js 应用程序。 这是我的网站:frinksmovement.com 当我转到未定义的子域(例如 frinksmovement.com/abc)时,它应该显示自定义 404 页面,但它会加载我的主页。 这不会发生在我的本地机器上。 这是我的 next.config.js:

module.exports = {
  webpack: (config) => {
    config.module.rules.push({
      test: /\.(graphql|gql)$/,
      exclude: /node_modules/,
      use: {
        loader: "graphql-tag/loader",
      },
    });
    return config;
  },
  async redirects() {
    return [
      {
        source: "/gornation",
        destination: "https://www.gornation.com/?ref=0j-iwl-pbxrv",
        permanent: true,
      },
    ];
  },
  trailingSlash: true,
};

编辑:您的意思不是子域,而是不同的路径页面,NextJS 为您提供了处理自定义 404 页面的内置方式。 给你: https ://nextjs.org/docs/advanced-features/custom-error-page

我发现了一个类似的问题,不幸的是,这可能意味着你不能。 子域基本上意味着转发到不同的 ip:port 组合,就像您为不同的 React 应用程序键入 localhost:3001 或 localhost:3002 一样,这就是子域试图隐藏的内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM