mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-19 15:10:58 +00:00
docs: add routeNameSplitter
example in migration docs (#25838)
This commit is contained in:
parent
41f6a0a3a0
commit
f4173b362b
@ -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
|
#### 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.
|
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.
|
||||||
|
Loading…
Reference in New Issue
Block a user