【问题标题】:trailing slashes, routing me to a different page in next.js尾部斜杠,将我路由到 next.js 中的不同页面
【发布时间】:2020-04-16 12:32:55
【问题描述】:

我正在使用 nextjs 在我的应用程序中启用 SSR。应用结构为:

  • 组件 -
    • component1.js
  • 公开 -
    • img1.png
  • 页 -
    • /订单 [订购].js
    • [国家].js
    • 联系我们.js
    • review.js

如果我执行 'localhost:3000/contact-us/' ,它会将我路由到 [country].js。 我认为当我们执行 /contact-us/ 时,它会将其视为文件夹,但文件夹实际上并不存在,它需要进入该目录的第一页。

我尝试在下一个配置中使用 exportTrailingSlashes: false 但没有帮助。

【问题讨论】:

    标签: next.js


    【解决方案1】:

    我认为避免这种情况的最佳方法是将您的[country].js 页面放在/countries 文件夹中。这将使您的页面看起来像:

    pages -
      /order
        [order].js
      /country
        [country].js
      contact-us.js
      review.js
    

    然后你可以通过http://localhost:3000/country/[country]到达国家端点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-14
      • 2014-07-09
      • 2020-03-21
      • 1970-01-01
      相关资源
      最近更新 更多