简体   繁体   English

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

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

I have a Next.js app with a custom 404 page.我有一个带有自定义 404 页面的 Next.js 应用程序。 This is my website: frinksmovement.com When I go to a subdomain that isn't defined (for example frinksmovement.com/abc), it should show the custom 404 page but it load my homepage.这是我的网站:frinksmovement.com 当我转到未定义的子域(例如 frinksmovement.com/abc)时,它应该显示自定义 404 页面,但它会加载我的主页。 This doesn't happen on my local machine.这不会发生在我的本地机器上。 This is my next.config.js:这是我的 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,
};

Edit: It's not subdomain you mean, it's a different path or page , NextJS provides you with a built in way to handle custom 404 pages.编辑:您的意思不是子域,而是不同的路径页面,NextJS 为您提供了处理自定义 404 页面的内置方式。 Here you go: https://nextjs.org/docs/advanced-features/custom-error-page给你: https ://nextjs.org/docs/advanced-features/custom-error-page

I found a similar question that might unfortunately mean that you can't.我发现了一个类似的问题,不幸的是,这可能意味着你不能。 A subdomain is basically meant to forward to a different ip:port combination, the same way you type localhost:3001 or localhost:3002 for different React applications, that's what a subdomain tries to hide.子域基本上意味着转发到不同的 ip:port 组合,就像您为不同的 React 应用程序键入 localhost:3001 或 localhost:3002 一样,这就是子域试图隐藏的内容。

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

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