@nuxt/docs-nightly 5.0.0-29741325.e71f6f2a → 5.0.0-29741395.1dfe8e50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/4.api/5.kit/7.pages.md +32 -1
- package/package.json +1 -1
package/4.api/5.kit/7.pages.md
CHANGED
|
@@ -51,11 +51,42 @@ function extendPages (callback: (pages: NuxtPage[]) => void): void
|
|
|
51
51
|
| `name` | `string` | `false` | The name of the route. Useful for programmatic navigation and identifying routes. |
|
|
52
52
|
| `path` | `string` | `false` | The route URL path. If not set, Nuxt will infer it from the file location. |
|
|
53
53
|
| `file` | `string` | `false` | Path to the Vue file that should be used as the component for the route. |
|
|
54
|
-
| `meta` | `
|
|
54
|
+
| `meta` | `NuxtPageMeta`{lang="ts"} | `false` | Custom metadata for the route. Can be used in layouts, middlewares, or navigation guards. |
|
|
55
55
|
| `alias` | `string[] \| string`{lang="ts"} | `false` | One or more alias paths for the route. Useful for supporting multiple URLs. |
|
|
56
56
|
| `redirect` | `RouteLocationRaw`{lang="ts"} | `false` | Redirect rule for the route. Supports named routes, objects, or string paths. |
|
|
57
57
|
| `children` | `NuxtPage[]`{lang="ts"} | `false` | Nested child routes under this route for layout or view nesting. |
|
|
58
58
|
|
|
59
|
+
### Typing Custom Page Metadata
|
|
60
|
+
|
|
61
|
+
You can augment the `NuxtPageMeta` interface to add type-safe custom metadata for pages when using `extendPages` or the `pages:extend` hook:
|
|
62
|
+
|
|
63
|
+
```ts [index.d.ts]
|
|
64
|
+
declare module '@nuxt/schema' {
|
|
65
|
+
interface NuxtPageMeta {
|
|
66
|
+
requiresAuth?: boolean
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export {}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```ts [modules/auth.ts]
|
|
74
|
+
import { defineNuxtModule, extendPages } from '@nuxt/kit'
|
|
75
|
+
|
|
76
|
+
export default defineNuxtModule({
|
|
77
|
+
setup () {
|
|
78
|
+
extendPages((pages) => {
|
|
79
|
+
for (const page of pages) {
|
|
80
|
+
// requiresAuth is now typed as boolean | undefined
|
|
81
|
+
if (page.meta?.requiresAuth) {
|
|
82
|
+
// ...
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
```
|
|
89
|
+
|
|
59
90
|
## `extendRouteRules`
|
|
60
91
|
|
|
61
92
|
Nuxt is powered by the [Nitro](https://nitro.build/) server engine. With Nitro, you can incorporate high-level logic directly into your configuration, which is useful for actions like redirects, proxying, caching, and appending headers to routes. This configuration works by associating route patterns with specific route settings.
|