You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Next.js中根路径主页与Catch-all Route共存的构建报错问题咨询

Next.js中根路径主页与Catch-all Route共存的构建报错问题咨询

我最近在配置Next.js路由时碰到了个麻烦,想请大家帮忙看看。我的需求很明确:让根路径/作为独立的主页,同时用[...slug]这个catch-all路由来承接所有其他的路径。

目前我的项目路由结构是这样的:

app/  
├── (home)/  
│   ├── layout.tsx  
│   └── page.tsx  
└── [...slug]/
    ├── layout.tsx
    └── page.tsx
├── layout.tsx  
└── page.tsx

但在执行next build进行构建的时候,却触发了预渲染错误,具体的报错日志如下:

Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error

Error: The provided export path '/' doesn't match the '/[...slug]' page.

Read more: https://nextjs.org/docs/messages/export-path-mismatch

at getParams (C:\git\adinsure-docs-fumadocs-portal\node_modules\next\dist\export\helpers\get-params.js:27:15)

at exportPageImpl (C:\git\adinsure-docs-fumadocs-portal\node_modules\next\dist\export\worker.js:108:43)

at C:\git\adinsure-docs-fumadocs-portal\node_modules\next\dist\export\worker.js:350:108

at turborepoTraceAccess (C:\git\adinsure-docs-fumadocs-portal\node_modules\next\dist\build\turborepo-access-trace\helpers.js:36:51)

at C:\git\adinsure-docs-fumadocs-portal\node_modules\next\dist\export\worker.js:350:103

at Span.traceAsyncFn (C:\git\adinsure-docs-fumadocs-portal\node_modules\next\dist\trace\trace.js:157:26)

at exportPage (C:\git\adinsure-docs-fumadocs-portal\node_modules\next\dist\export\worker.js:350:39)

at exportPageWithRetry (C:\git\adinsure-docs-fumadocs-portal\node_modules\next\dist\export\worker.js:239:21)

at C:\git\adinsure-docs-fumadocs-portal\node_modules\next\dist\export\worker.js:321:72

at Array.map (<anonymous>)

Export encountered an error on /[...slug]/page: /, exiting the build.

⨯ Static worker exited with code: 1 and signal: null

error Command failed with exit code 1  

说起来有点奇怪,之前这个配置好像还能正常运行,不知道为啥突然就报错了。现在我想找一个合规且稳定的方案,来实现根路径主页和catch-all路由共存的需求。

我的Next.js版本是15.0.1。

备注:内容来源于stack exchange,提问作者Vanja Stojanović

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 20:14:49