我这里有个很简单的问题。在我们的代码库中,应用程序分支中的几乎所有页面都位于/app
基路径之外,因此我们在next.config.js
文件中定义了这样的属性:
const moduleExports = {
basePath: '/app',
reactStrictMode: true,
};
但是,对于一个新特性,我们希望页面在单独的路径上存在-- domain.com/a/[slug]
而不是domain.com/app/a/[slug]
。有什么方法可以将这个特定页面从basePath
属性中排除出来吗?提前谢谢。
发布于 2022-10-12 07:53:34
据我所知,不能将页面排除在basePath
之外,但是,可以使用一些工作来实现类似的结果:
next.config.js
中使用rewrites
和:path*
来保持动态路由的功能:const moduleExports = {
basePath: '/app',
reactStrictMode: true,
async rewrites() {
return [
{
source: '/a/:path*',
destination: '/app/a/:path*',
},
]
},
};
basePath
属性。如果您使用的是多带,或者使用的是涡轮增压器,这是行不通的。相反,您可以创建一个文件夹app
,并将除/a/[slug]
路由之外的所有应用程序放在那里:pages/
├─ a/
│ ├─ [slug]
├─ app/
├─ rest of your app
https://stackoverflow.com/questions/74033626
复制相似问题