[英]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.