簡體   English   中英

如何使 NextJS 中的頁面路徑不區分大小寫

[英]How to make path for pages in NextJS case insensitive

我在pages文件夾下有一個名為about.tsx文件。 所以頁面的路徑是/about ,我可以通過訪問example.com/about來訪問該頁面。 但是,如果我訪問example.com/About ,它將重定向到 404 頁面。

我檢查了 Nextjs 存儲庫,似乎這是預期的行為。 因此,是否有一種解決方法可以使路徑不區分大小寫,以便example.com/About也可以工作並將用戶定向到/about頁面?

我同意這是 Next.js 的行為,他們只處理確切的頁面名稱about而不是about & About使用相同的文件page/about.tsx

但解決方案是按照本指南https://nextjs.org/docs/api-reference繼續實施主頁(例如:about.tsx)並設置其他頁面以重定向到該頁面(例如:關於 -> 關於) /next.config.js/redirects

// next.config.js
module.exports = {
  async redirects() {
    return [
      {
        source: '/About',
        destination: '/about',
        permanent: true,
      },
    ]
  },
}

// Set permanent:true for 301 redirect  & clean SEO!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM