admin管理员组文章数量:1356961
I have a catch-all route on which i wish to render different pages depending on the slugs - this is not hard to achieve. The following is my structure:
app/
├── (home)/
│ ├── layout.tsx
│ └── page.tsx
└── [...slug]/
├── layout.tsx
└── page.tsx
├── layout.tsx
└── page.tsx
Now my question is, how can I - or can I - have a home page on the root URL '/' and all the other routes handled by the [...slug] catcher? The reason I am asking is because during `next build`:
Error occurred prerendering page "/". Read more: []()
Error: The provided export path '/' doesn't match the '/\[...slug\]' page.
Read more: []()
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
(It might seem weird, but the setup was working, for some reason, it dropped again, and now I'm looking for a more proper solution)
My Next version is: 15.0.1
I have a catch-all route on which i wish to render different pages depending on the slugs - this is not hard to achieve. The following is my structure:
app/
├── (home)/
│ ├── layout.tsx
│ └── page.tsx
└── [...slug]/
├── layout.tsx
└── page.tsx
├── layout.tsx
└── page.tsx
Now my question is, how can I - or can I - have a home page on the root URL '/' and all the other routes handled by the [...slug] catcher? The reason I am asking is because during `next build`:
Error occurred prerendering page "/". Read more: [https://nextjs./docs/messages/prerender-error](https://nextjs./docs/messages/prerender-error)
Error: The provided export path '/' doesn't match the '/\[...slug\]' page.
Read more: [https://nextjs./docs/messages/export-path-mismatch](https://nextjs./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](http://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
(It might seem weird, but the setup was working, for some reason, it dropped again, and now I'm looking for a more proper solution)
My Next version is: 15.0.1
Share Improve this question asked Mar 27 at 22:55 Vanja StojanovićVanja Stojanović 14710 bronze badges1 Answer
Reset to default 0So it happened that I got an answer.
In my [...slug]/page.tsx
I just filtered out the root path before returning all the pages:
export async function generateStaticParams() {
const pages = await getPages();
return pages
.filter(page => page.path !== '/') // Exclude root path
.map(page => ({
slug: page.path.split('/').filter(Boolean)
}));
}
and (the thing I think actually helped) was turning off trailing slashes in the next.config.mjs
:
/** @type {import('next').NextConfig} */
const config = {
output: 'standalone',
reactStrictMode: true,
...,
trailingSlash: false,
};
本文标签: javascriptCatchall route with a default static page In NextjsStack Overflow
版权声明:本文标题:javascript - Catch-all route with a default static page In Next.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744064255a2584695.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论