rsnext/errors/conflicting-ssg-paths.md
JJ Kasper 9caca2784c
Add proper error when conflicting paths are detected (#20918)
This helps catch conflicting paths returned from `getStaticPaths` with a friendly error

<details>

<summary>
Preview of error
</summary>


<img width="962" alt="Screen Shot 2021-01-08 at 5 03 04 PM" src="https://user-images.githubusercontent.com/22380829/104074719-6e481100-51d6-11eb-9397-938aee3ae30b.png">
<img width="962" alt="Screen Shot 2021-01-08 at 5 03 41 PM" src="https://user-images.githubusercontent.com/22380829/104074722-6f793e00-51d6-11eb-90f6-7cdf9882bf00.png">

</details>




Closes: https://github.com/vercel/next.js/issues/19527
2021-01-11 20:50:17 +00:00

68 lines
1.5 KiB
Markdown

# Conflicting SSG Paths
#### Why This Error Occurred
In your `getStaticPaths` function for one of your pages you returned conflicting paths. All page paths must be unique and duplicates are not allowed.
#### Possible Ways to Fix It
Remove any conflicting paths shown in the error message and only return them from one `getStaticPaths`.
Example conflicting paths:
```jsx
// pages/hello/world.js
export default function Hello() {
return 'hello world!'
}
// pages/[...catchAll].js
export const getStaticProps = () => ({ props: {} })
export const getStaticPaths = () => ({
paths: [
// this conflicts with the /hello/world.js page, remove to resolve error
'/hello/world',
'/another',
],
fallback: false,
})
export default function CatchAll() {
return 'Catch-all page'
}
```
Example conflicting paths:
```jsx
// pages/blog/[slug].js
export const getStaticPaths = () => ({
paths: ['/blog/conflicting', '/blog/another'],
fallback: false,
})
export default function Blog() {
return 'Blog!'
}
// pages/[...catchAll].js
export const getStaticProps = () => ({ props: {} })
export const getStaticPaths = () => ({
paths: [
// this conflicts with the /blog/conflicting path above, remove to resolve error
'/blog/conflicting',
'/another',
],
fallback: false,
})
export default function CatchAll() {
return 'Catch-all page'
}
```
### Useful Links
- [`getStaticPaths` Documentation](https://nextjs.org/docs/basic-features/data-fetching#getstaticpaths-static-generation)