Skip to content

Commit

Permalink
docs: add routeNameSplitter example in migration docs (#25838)
Browse files Browse the repository at this point in the history
  • Loading branch information
bargel committed Mar 18, 2024
1 parent 41f6a0a commit f4173b3
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions docs/7.migration/2.configuration.md
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

0 comments on commit f4173b3

Please sign in to comment.