Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add missing routeNameSplitter alternative example #25838

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions docs/7.migration/2.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,44 @@ Nuxt configuration will be loaded using [`unjs/jiti`](https://github.com/unjs/ji

::

1. If you were using `router.routeNameSplitter` you can achieve same result by updating route name generation logic in the new `pages:extend` hook:

::code-group

```ts [Nuxt 2]
export default {
router: {
routeNameSplitter: '/'
}
}

```ts [Nuxt 3]
import { createResolver } from '@nuxt/kit'

export default defineNuxtConfig({
hooks: {
'pages:extend' (routes) {
const routeNameSplitter = '/'
const root = createResolver(import.meta.url).resolve('./pages')

function updateName(routes) {
if (!routes) return

for (const route of routes) {
const relativePath = route.file.substring(root.length + 1)
route.name = relativePath.replace(/\//g, routeNameSplitter).slice(0, -4)

updateName(route.children)
}
}
updateName(routes)
},
},
})
```

::

#### ESM Syntax

Nuxt 3 is an [ESM native framework](/docs/guide/concepts/esm). Although [`unjs/jiti`](https://github.com/unjs/jiti) provides semi compatibility when loading `nuxt.config` file, avoid any usage of `require` and `module.exports` in this file.
Expand Down