docs: fix TypeScript errors for examples (#28403)

This commit is contained in:
AuroraTea 2024-08-05 21:58:10 +08:00 committed by GitHub
parent 754fc30e5d
commit 32f1573614
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 4 deletions

View File

@ -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 <RouterConfig> {
@ -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'