diff --git a/docs/2.guide/4.recipes/1.custom-routing.md b/docs/2.guide/4.recipes/1.custom-routing.md index b3e408c2a3..e3e777d0ca 100644 --- a/docs/2.guide/4.recipes/1.custom-routing.md +++ b/docs/2.guide/4.recipes/1.custom-routing.md @@ -39,6 +39,8 @@ You can add, change or remove pages from the scanned routes with the `pages:exte For example, to prevent creating routes for any `.ts` files: ```ts [nuxt.config.ts] +import type { NuxtPage } from '@nuxt/schema' + export default defineNuxtConfig({ hooks: { 'pages:extend' (pages) { @@ -51,9 +53,9 @@ export default defineNuxtConfig({ // remove routes function removePagesMatching (pattern: RegExp, pages: NuxtPage[] = []) { - const pagesToRemove = [] + const pagesToRemove: NuxtPage[] = [] for (const page of pages) { - if (pattern.test(page.file)) { + if (page.file && pattern.test(page.file)) { pagesToRemove.push(page) } else { removePagesMatching(pattern, page.children) @@ -85,7 +87,7 @@ On top of customizing options for [`vue-router`](https://router.vuejs.org/api/in This is the recommended way to specify [router options](/docs/api/nuxt-config#router). -```js [app/router.options.ts] +```ts [app/router.options.ts] import type { RouterConfig } from '@nuxt/schema' export default { @@ -99,6 +101,8 @@ Adding a router options file in this hook will switch on page-based routing, unl :: ```ts [nuxt.config.ts] +import { createResolver } from '@nuxt/kit' + export default defineNuxtConfig({ hooks: { 'pages:routerOptions' ({ files }) { @@ -166,7 +170,7 @@ export default defineNuxtConfig({ You can optionally override history mode using a function that accepts the base URL and returns the history mode. If it returns `null` or `undefined`, Nuxt will fallback to the default history. -```js [app/router.options.ts] +```ts [app/router.options.ts] import type { RouterConfig } from '@nuxt/schema' import { createMemoryHistory } from 'vue-router'