mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
When trying to generate my SSG docs site I couldn't figure out why the navigation links (`href="/about`) were not mapping to the generated files (e.g. `/out/about.html)`. `trailingSlash` was key to converting the files to `/out/about/index.html` to make the SSG links work properly. I've updated the trailingSlash docs to be clear how they affect SSG mode. It might also make sense to add this to the SSG guide as well. Co-authored-by: Steven <[email protected]>
27 lines
1.2 KiB
Plaintext
27 lines
1.2 KiB
Plaintext
---
|
|
title: trailingSlash
|
|
description: Configure Next.js pages to resolve with or without a trailing slash.
|
|
---
|
|
|
|
{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
|
|
|
|
By default Next.js will redirect urls with trailing slashes to their counterpart without a trailing slash. For example `/about/` will redirect to `/about`. You can configure this behavior to act the opposite way, where urls without trailing slashes are redirected to their counterparts with trailing slashes.
|
|
|
|
Open `next.config.js` and add the `trailingSlash` config:
|
|
|
|
```js filename="next.config.js"
|
|
module.exports = {
|
|
trailingSlash: true,
|
|
}
|
|
```
|
|
|
|
With this option set, urls like `/about` will redirect to `/about/`.
|
|
|
|
When used with [`output: "export"`](/docs/app/building-your-application/deploying/static-exports) configuration, the `/about` page will output `/about/index.html` (instead of the default `/about.html`).
|
|
|
|
## Version History
|
|
|
|
| Version | Changes |
|
|
| -------- | ---------------------- |
|
|
| `v9.5.0` | `trailingSlash` added. |
|