@nuxt/docs-nightly 4.1.3-29314777.50febbbb → 4.1.3-29316225.304409da
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/1.getting-started/03.configuration.md +19 -19
- package/1.getting-started/04.views.md +1 -1
- package/1.getting-started/05.assets.md +8 -2
- package/1.getting-started/06.styling.md +50 -40
- package/1.getting-started/07.routing.md +4 -4
- package/1.getting-started/08.seo-meta.md +46 -33
- package/1.getting-started/09.transitions.md +38 -33
- package/1.getting-started/10.data-fetching.md +47 -39
- package/1.getting-started/11.state-management.md +15 -8
- package/1.getting-started/12.error-handling.md +6 -4
- package/1.getting-started/13.server.md +3 -3
- package/1.getting-started/14.layers.md +18 -12
- package/1.getting-started/15.prerendering.md +24 -24
- package/1.getting-started/16.deployment.md +7 -7
- package/1.getting-started/17.testing.md +41 -41
- package/1.getting-started/18.upgrade.md +48 -66
- package/2.guide/1.directory-structure/1.app/1.components.md +36 -19
- package/2.guide/1.directory-structure/1.app/1.composables.md +7 -7
- package/2.guide/1.directory-structure/1.app/1.layouts.md +9 -5
- package/2.guide/1.directory-structure/1.app/1.middleware.md +20 -14
- package/2.guide/1.directory-structure/1.app/1.pages.md +19 -17
- package/2.guide/1.directory-structure/1.app/1.plugins.md +17 -17
- package/2.guide/1.directory-structure/1.app/1.utils.md +1 -1
- package/2.guide/1.directory-structure/1.app/3.app-config.md +6 -6
- package/2.guide/1.directory-structure/1.app/3.error.md +4 -4
- package/2.guide/1.directory-structure/1.content.md +4 -1
- package/2.guide/1.directory-structure/1.modules.md +4 -4
- package/2.guide/1.directory-structure/1.public.md +1 -1
- package/2.guide/1.directory-structure/1.server.md +28 -28
- package/2.guide/1.directory-structure/1.shared.md +1 -1
- package/2.guide/2.concepts/1.auto-imports.md +11 -11
- package/2.guide/2.concepts/2.vuejs-development.md +5 -5
- package/2.guide/2.concepts/3.rendering.md +14 -12
- package/2.guide/2.concepts/5.modules.md +2 -2
- package/2.guide/2.concepts/7.esm.md +14 -12
- package/2.guide/2.concepts/8.typescript.md +4 -4
- package/2.guide/3.going-further/1.events.md +2 -2
- package/2.guide/3.going-further/1.experimental-features.md +234 -73
- package/2.guide/3.going-further/1.features.md +44 -9
- package/2.guide/3.going-further/1.internals.md +15 -15
- package/2.guide/3.going-further/10.runtime-config.md +7 -7
- package/2.guide/3.going-further/2.hooks.md +8 -8
- package/2.guide/3.going-further/3.modules.md +76 -74
- package/2.guide/3.going-further/4.kit.md +3 -3
- package/2.guide/3.going-further/6.nuxt-app.md +1 -1
- package/2.guide/3.going-further/7.layers.md +50 -41
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +19 -19
- package/2.guide/4.recipes/2.vite-plugin.md +3 -3
- package/2.guide/4.recipes/3.custom-usefetch.md +9 -9
- package/2.guide/4.recipes/4.sessions-and-authentication.md +33 -19
- package/2.guide/5.best-practices/performance.md +8 -8
- package/3.api/1.components/1.client-only.md +6 -3
- package/3.api/1.components/1.nuxt-client-fallback.md +9 -6
- package/3.api/1.components/11.teleports.md +4 -1
- package/3.api/1.components/12.nuxt-route-announcer.md +7 -7
- package/3.api/1.components/13.nuxt-time.md +44 -17
- package/3.api/1.components/2.nuxt-page.md +2 -2
- package/3.api/1.components/3.nuxt-layout.md +9 -4
- package/3.api/1.components/4.nuxt-link.md +38 -18
- package/3.api/1.components/6.nuxt-error-boundary.md +11 -9
- package/3.api/2.composables/on-prehydrate.md +2 -2
- package/3.api/2.composables/use-async-data.md +11 -11
- package/3.api/2.composables/use-cookie.md +26 -18
- package/3.api/2.composables/use-error.md +1 -1
- package/3.api/2.composables/use-fetch.md +13 -13
- package/3.api/2.composables/use-head-safe.md +5 -5
- package/3.api/2.composables/use-head.md +2 -2
- package/3.api/2.composables/use-hydration.md +5 -5
- package/3.api/2.composables/use-loading-indicator.md +10 -10
- package/3.api/2.composables/use-nuxt-app.md +9 -9
- package/3.api/2.composables/use-nuxt-data.md +7 -7
- package/3.api/2.composables/use-preview-mode.md +12 -15
- package/3.api/2.composables/use-request-fetch.md +1 -1
- package/3.api/2.composables/use-request-headers.md +3 -3
- package/3.api/2.composables/use-response-header.md +7 -8
- package/3.api/2.composables/use-route-announcer.md +3 -3
- package/3.api/2.composables/use-router.md +5 -3
- package/3.api/2.composables/use-runtime-config.md +6 -6
- package/3.api/2.composables/use-runtime-hook.md +1 -1
- package/3.api/2.composables/use-seo-meta.md +1 -1
- package/3.api/2.composables/use-server-seo-meta.md +1 -1
- package/3.api/2.composables/use-state.md +3 -3
- package/3.api/3.utils/$fetch.md +5 -3
- package/3.api/3.utils/abort-navigation.md +2 -2
- package/3.api/3.utils/add-route-middleware.md +3 -3
- package/3.api/3.utils/call-once.md +3 -3
- package/3.api/3.utils/clear-error.md +1 -1
- package/3.api/3.utils/clear-nuxt-data.md +2 -2
- package/3.api/3.utils/clear-nuxt-state.md +2 -2
- package/3.api/3.utils/create-error.md +1 -1
- package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
- package/3.api/3.utils/define-nuxt-component.md +5 -5
- package/3.api/3.utils/define-nuxt-plugin.md +11 -11
- package/3.api/3.utils/define-nuxt-route-middleware.md +2 -2
- package/3.api/3.utils/define-page-meta.md +14 -14
- package/3.api/3.utils/define-route-rules.md +3 -3
- package/3.api/3.utils/navigate-to.md +9 -9
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/prerender-routes.md +2 -2
- package/3.api/3.utils/refresh-cookie.md +3 -3
- package/3.api/3.utils/refresh-nuxt-data.md +9 -4
- package/3.api/3.utils/reload-nuxt-app.md +2 -2
- package/3.api/3.utils/set-response-status.md +1 -1
- package/3.api/3.utils/show-error.md +2 -2
- package/3.api/3.utils/update-app-config.md +2 -1
- package/3.api/4.commands/prepare.md +4 -0
- package/3.api/5.kit/1.modules.md +36 -36
- package/3.api/5.kit/10.templates.md +8 -6
- package/3.api/5.kit/11.nitro.md +62 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +1 -0
- package/3.api/5.kit/15.examples.md +2 -2
- package/3.api/5.kit/16.layers.md +26 -26
- package/3.api/5.kit/3.compatibility.md +12 -12
- package/3.api/5.kit/4.autoimports.md +12 -12
- package/3.api/5.kit/5.components.md +5 -5
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +4 -4
- package/3.api/5.kit/8.layout.md +1 -1
- package/3.api/5.kit/9.plugins.md +5 -4
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/3.api/6.nuxt-config.md +293 -858
- package/6.bridge/1.overview.md +1 -1
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +2 -2
- package/6.bridge/3.bridge-composition-api.md +2 -2
- package/6.bridge/4.plugins-and-middleware.md +5 -5
- package/6.bridge/5.nuxt3-compatible-api.md +11 -8
- package/6.bridge/6.meta.md +15 -14
- package/6.bridge/8.nitro.md +2 -2
- package/6.bridge/9.vite.md +3 -3
- package/7.migration/2.configuration.md +17 -15
- package/7.migration/4.meta.md +17 -14
- package/7.migration/5.plugins-and-middleware.md +5 -5
- package/7.migration/6.pages-and-layouts.md +15 -11
- package/7.migration/7.component-options.md +3 -3
- package/7.migration/8.runtime-config.md +3 -3
- package/package.json +1 -1
|
@@ -36,16 +36,16 @@ You can configure fully typed, per-environment overrides in your nuxt.config
|
|
|
36
36
|
export default defineNuxtConfig({
|
|
37
37
|
$production: {
|
|
38
38
|
routeRules: {
|
|
39
|
-
'/**': { isr: true }
|
|
40
|
-
}
|
|
39
|
+
'/**': { isr: true },
|
|
40
|
+
},
|
|
41
41
|
},
|
|
42
42
|
$development: {
|
|
43
43
|
//
|
|
44
44
|
},
|
|
45
45
|
$env: {
|
|
46
46
|
staging: {
|
|
47
|
-
//
|
|
48
|
-
}
|
|
47
|
+
//
|
|
48
|
+
},
|
|
49
49
|
},
|
|
50
50
|
})
|
|
51
51
|
```
|
|
@@ -75,9 +75,9 @@ export default defineNuxtConfig({
|
|
|
75
75
|
apiSecret: '123',
|
|
76
76
|
// Keys within public are also exposed client-side
|
|
77
77
|
public: {
|
|
78
|
-
apiBase: '/api'
|
|
79
|
-
}
|
|
80
|
-
}
|
|
78
|
+
apiBase: '/api',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
81
|
})
|
|
82
82
|
```
|
|
83
83
|
|
|
@@ -110,9 +110,9 @@ export default defineAppConfig({
|
|
|
110
110
|
theme: {
|
|
111
111
|
dark: true,
|
|
112
112
|
colors: {
|
|
113
|
-
primary: '#ff0000'
|
|
114
|
-
}
|
|
115
|
-
}
|
|
113
|
+
primary: '#ff0000',
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
116
|
})
|
|
117
117
|
```
|
|
118
118
|
|
|
@@ -178,12 +178,12 @@ If you need to pass options to `@vitejs/plugin-vue` or `@vitejs/plugin-vue-jsx`,
|
|
|
178
178
|
export default defineNuxtConfig({
|
|
179
179
|
vite: {
|
|
180
180
|
vue: {
|
|
181
|
-
customElement: true
|
|
181
|
+
customElement: true,
|
|
182
182
|
},
|
|
183
183
|
vueJsx: {
|
|
184
|
-
mergeProps: true
|
|
185
|
-
}
|
|
186
|
-
}
|
|
184
|
+
mergeProps: true,
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
187
|
})
|
|
188
188
|
```
|
|
189
189
|
|
|
@@ -199,9 +199,9 @@ export default defineNuxtConfig({
|
|
|
199
199
|
loaders: {
|
|
200
200
|
vue: {
|
|
201
201
|
hotReload: true,
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
205
|
})
|
|
206
206
|
```
|
|
207
207
|
|
|
@@ -214,8 +214,8 @@ You may need to enable experimental features in Vue, such as `propsDestructure`.
|
|
|
214
214
|
```ts twoslash [nuxt.config.ts]
|
|
215
215
|
export default defineNuxtConfig({
|
|
216
216
|
vue: {
|
|
217
|
-
propsDestructure: true
|
|
218
|
-
}
|
|
217
|
+
propsDestructure: true,
|
|
218
|
+
},
|
|
219
219
|
})
|
|
220
220
|
```
|
|
221
221
|
|
|
@@ -21,7 +21,10 @@ For example, referencing an image file in the `public/img/` directory, available
|
|
|
21
21
|
|
|
22
22
|
```vue [app/app.vue]
|
|
23
23
|
<template>
|
|
24
|
-
<img
|
|
24
|
+
<img
|
|
25
|
+
src="/img/nuxt.png"
|
|
26
|
+
alt="Discover Nuxt"
|
|
27
|
+
>
|
|
25
28
|
</template>
|
|
26
29
|
```
|
|
27
30
|
|
|
@@ -39,7 +42,10 @@ For example, referencing an image file that will be processed if a build tool is
|
|
|
39
42
|
|
|
40
43
|
```vue [app/app.vue]
|
|
41
44
|
<template>
|
|
42
|
-
<img
|
|
45
|
+
<img
|
|
46
|
+
src="~/assets/img/nuxt.png"
|
|
47
|
+
alt="Discover Nuxt"
|
|
48
|
+
>
|
|
43
49
|
</template>
|
|
44
50
|
```
|
|
45
51
|
|
|
@@ -41,7 +41,7 @@ The natural place for your stylesheets is the [`app/assets/` directory](/docs/4.
|
|
|
41
41
|
|
|
42
42
|
```ts [nuxt.config.ts]
|
|
43
43
|
export default defineNuxtConfig({
|
|
44
|
-
css: ['~/assets/css/main.css']
|
|
44
|
+
css: ['~/assets/css/main.css'],
|
|
45
45
|
})
|
|
46
46
|
```
|
|
47
47
|
|
|
@@ -113,7 +113,7 @@ The package can also be referenced as a string in the css property of your Nuxt
|
|
|
113
113
|
|
|
114
114
|
```ts [nuxt.config.ts]
|
|
115
115
|
export default defineNuxtConfig({
|
|
116
|
-
css: ['animate.css']
|
|
116
|
+
css: ['animate.css'],
|
|
117
117
|
})
|
|
118
118
|
```
|
|
119
119
|
|
|
@@ -127,9 +127,9 @@ You can manipulate the head with the [`app.head`](/docs/4.x/api/nuxt-config#head
|
|
|
127
127
|
export default defineNuxtConfig({
|
|
128
128
|
app: {
|
|
129
129
|
head: {
|
|
130
|
-
link: [{ rel: 'stylesheet', href: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css' }]
|
|
131
|
-
}
|
|
132
|
-
}
|
|
130
|
+
link: [{ rel: 'stylesheet', href: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css' }],
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
133
|
})
|
|
134
134
|
```
|
|
135
135
|
|
|
@@ -141,7 +141,7 @@ You can use the useHead composable to dynamically set a value in your head in yo
|
|
|
141
141
|
|
|
142
142
|
```ts twoslash
|
|
143
143
|
useHead({
|
|
144
|
-
link: [{ rel: 'stylesheet', href: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css' }]
|
|
144
|
+
link: [{ rel: 'stylesheet', href: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css' }],
|
|
145
145
|
})
|
|
146
146
|
```
|
|
147
147
|
|
|
@@ -198,7 +198,7 @@ Alternatively, you can use the `css` property of your Nuxt configuration.
|
|
|
198
198
|
|
|
199
199
|
```ts twoslash [nuxt.config.ts]
|
|
200
200
|
export default defineNuxtConfig({
|
|
201
|
-
css: ['~/assets/scss/main.scss']
|
|
201
|
+
css: ['~/assets/scss/main.scss'],
|
|
202
202
|
})
|
|
203
203
|
```
|
|
204
204
|
|
|
@@ -234,11 +234,11 @@ export default defineNuxtConfig({
|
|
|
234
234
|
css: {
|
|
235
235
|
preprocessorOptions: {
|
|
236
236
|
scss: {
|
|
237
|
-
additionalData: '@use "~/assets/_colors.scss" as *;'
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
237
|
+
additionalData: '@use "~/assets/_colors.scss" as *;',
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
242
|
})
|
|
243
243
|
```
|
|
244
244
|
|
|
@@ -248,11 +248,11 @@ export default defineNuxtConfig({
|
|
|
248
248
|
css: {
|
|
249
249
|
preprocessorOptions: {
|
|
250
250
|
sass: {
|
|
251
|
-
additionalData: '@use "~/assets/_colors.sass" as *\n'
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
251
|
+
additionalData: '@use "~/assets/_colors.sass" as *\n',
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
256
|
})
|
|
257
257
|
```
|
|
258
258
|
|
|
@@ -267,13 +267,12 @@ Vite has made available an [experimental option](https://vite.dev/config/shared-
|
|
|
267
267
|
You can enable this in your `nuxt.config`:
|
|
268
268
|
|
|
269
269
|
```ts
|
|
270
|
-
|
|
271
270
|
export default defineNuxtConfig({
|
|
272
271
|
vite: {
|
|
273
272
|
css: {
|
|
274
|
-
preprocessorMaxWorkers: true // number of CPUs minus 1
|
|
275
|
-
}
|
|
276
|
-
}
|
|
273
|
+
preprocessorMaxWorkers: true, // number of CPUs minus 1
|
|
274
|
+
},
|
|
275
|
+
},
|
|
277
276
|
})
|
|
278
277
|
```
|
|
279
278
|
|
|
@@ -298,14 +297,17 @@ You can leverage Vue SFC features to style your components with class and style
|
|
|
298
297
|
const isActive = ref(true)
|
|
299
298
|
const hasError = ref(false)
|
|
300
299
|
const classObject = reactive({
|
|
301
|
-
active: true,
|
|
302
|
-
'text-danger': false
|
|
300
|
+
'active': true,
|
|
301
|
+
'text-danger': false,
|
|
303
302
|
})
|
|
304
303
|
</script>
|
|
305
304
|
|
|
306
305
|
<template>
|
|
307
|
-
<div
|
|
308
|
-
|
|
306
|
+
<div
|
|
307
|
+
class="static"
|
|
308
|
+
:class="{ 'active': isActive, 'text-danger': hasError }"
|
|
309
|
+
/>
|
|
310
|
+
<div :class="classObject" />
|
|
309
311
|
</template>
|
|
310
312
|
```
|
|
311
313
|
|
|
@@ -315,13 +317,13 @@ const isActive = ref(true)
|
|
|
315
317
|
const error = ref(null)
|
|
316
318
|
|
|
317
319
|
const classObject = computed(() => ({
|
|
318
|
-
active: isActive.value && !error.value,
|
|
319
|
-
'text-danger': error.value && error.value.type === 'fatal'
|
|
320
|
+
'active': isActive.value && !error.value,
|
|
321
|
+
'text-danger': error.value && error.value.type === 'fatal',
|
|
320
322
|
}))
|
|
321
323
|
</script>
|
|
322
324
|
|
|
323
325
|
<template>
|
|
324
|
-
<div :class="classObject"
|
|
326
|
+
<div :class="classObject" />
|
|
325
327
|
</template>
|
|
326
328
|
```
|
|
327
329
|
|
|
@@ -332,7 +334,7 @@ const errorClass = ref('text-danger')
|
|
|
332
334
|
</script>
|
|
333
335
|
|
|
334
336
|
<template>
|
|
335
|
-
<div :class="[{ active: isActive }, errorClass]"
|
|
337
|
+
<div :class="[{ active: isActive }, errorClass]" />
|
|
336
338
|
</template>
|
|
337
339
|
```
|
|
338
340
|
|
|
@@ -344,9 +346,9 @@ const styleObject = reactive({ color: 'red', fontSize: '13px' })
|
|
|
344
346
|
</script>
|
|
345
347
|
|
|
346
348
|
<template>
|
|
347
|
-
<div :style="{ color: activeColor, fontSize: fontSize + 'px' }"
|
|
348
|
-
<div :style="[baseStyles, overridingStyles]"
|
|
349
|
-
<div :style="styleObject"
|
|
349
|
+
<div :style="{ color: activeColor, fontSize: fontSize + 'px' }" />
|
|
350
|
+
<div :style="[baseStyles, overridingStyles]" />
|
|
351
|
+
<div :style="styleObject" />
|
|
350
352
|
</template>
|
|
351
353
|
```
|
|
352
354
|
|
|
@@ -361,11 +363,13 @@ The binding will be dynamic, meaning that if the variable value changes, the sty
|
|
|
361
363
|
|
|
362
364
|
```vue
|
|
363
365
|
<script setup lang="ts">
|
|
364
|
-
const color = ref(
|
|
366
|
+
const color = ref('red')
|
|
365
367
|
</script>
|
|
366
368
|
|
|
367
369
|
<template>
|
|
368
|
-
<div class="text">
|
|
370
|
+
<div class="text">
|
|
371
|
+
hello
|
|
372
|
+
</div>
|
|
369
373
|
</template>
|
|
370
374
|
|
|
371
375
|
<style>
|
|
@@ -381,7 +385,9 @@ The scoped attribute allows you to style components in isolation. The styles dec
|
|
|
381
385
|
|
|
382
386
|
```vue
|
|
383
387
|
<template>
|
|
384
|
-
<div class="example">
|
|
388
|
+
<div class="example">
|
|
389
|
+
hi
|
|
390
|
+
</div>
|
|
385
391
|
</template>
|
|
386
392
|
|
|
387
393
|
<style scoped>
|
|
@@ -397,7 +403,9 @@ You can use [CSS Modules](https://github.com/css-modules/css-modules) with the m
|
|
|
397
403
|
|
|
398
404
|
```vue
|
|
399
405
|
<template>
|
|
400
|
-
<p :class="$style.red">
|
|
406
|
+
<p :class="$style.red">
|
|
407
|
+
This should be red
|
|
408
|
+
</p>
|
|
401
409
|
</template>
|
|
402
410
|
|
|
403
411
|
<style module>
|
|
@@ -451,9 +459,9 @@ export default defineNuxtConfig({
|
|
|
451
459
|
postcss: {
|
|
452
460
|
plugins: {
|
|
453
461
|
'postcss-nested': {},
|
|
454
|
-
'postcss-custom-media': {}
|
|
455
|
-
}
|
|
456
|
-
}
|
|
462
|
+
'postcss-custom-media': {},
|
|
463
|
+
},
|
|
464
|
+
},
|
|
457
465
|
})
|
|
458
466
|
```
|
|
459
467
|
|
|
@@ -558,7 +566,9 @@ export default defineNuxtConfig({
|
|
|
558
566
|
// start from the end of the array and go to the beginning
|
|
559
567
|
for (let i = css.length - 1; i >= 0; i--) {
|
|
560
568
|
// if it starts with 'entry', remove it from the list
|
|
561
|
-
if (css[i].startsWith('entry'))
|
|
569
|
+
if (css[i].startsWith('entry')) {
|
|
570
|
+
css.splice(i, 1)
|
|
571
|
+
}
|
|
562
572
|
}
|
|
563
573
|
}
|
|
564
574
|
},
|
|
@@ -101,7 +101,7 @@ Example of an `auth` middleware protecting the `/dashboard` page:
|
|
|
101
101
|
::code-group
|
|
102
102
|
|
|
103
103
|
```ts twoslash [middleware/auth.ts]
|
|
104
|
-
function isAuthenticated(): boolean { return false }
|
|
104
|
+
function isAuthenticated (): boolean { return false }
|
|
105
105
|
// ---cut---
|
|
106
106
|
export default defineNuxtRouteMiddleware((to, from) => {
|
|
107
107
|
// isAuthenticated() is an example method verifying if a user is authenticated
|
|
@@ -114,7 +114,7 @@ export default defineNuxtRouteMiddleware((to, from) => {
|
|
|
114
114
|
```vue twoslash [pages/dashboard.vue]
|
|
115
115
|
<script setup lang="ts">
|
|
116
116
|
definePageMeta({
|
|
117
|
-
middleware: 'auth'
|
|
117
|
+
middleware: 'auth',
|
|
118
118
|
})
|
|
119
119
|
</script>
|
|
120
120
|
|
|
@@ -138,10 +138,10 @@ If you have a more complex use case, then you can use anonymous route middleware
|
|
|
138
138
|
```vue twoslash [pages/posts/[id\\].vue]
|
|
139
139
|
<script setup lang="ts">
|
|
140
140
|
definePageMeta({
|
|
141
|
-
validate
|
|
141
|
+
validate (route) {
|
|
142
142
|
// Check if the id is made up of digits
|
|
143
143
|
return typeof route.params.id === 'string' && /^\d+$/.test(route.params.id)
|
|
144
|
-
}
|
|
144
|
+
},
|
|
145
145
|
})
|
|
146
146
|
</script>
|
|
147
147
|
```
|
|
@@ -27,9 +27,9 @@ export default defineNuxtConfig({
|
|
|
27
27
|
},
|
|
28
28
|
link: [
|
|
29
29
|
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
|
|
30
|
-
]
|
|
31
|
-
}
|
|
32
|
-
}
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
33
|
})
|
|
34
34
|
```
|
|
35
35
|
|
|
@@ -51,8 +51,8 @@ export default defineNuxtConfig({
|
|
|
51
51
|
// update Nuxt defaults
|
|
52
52
|
charset: 'utf-16',
|
|
53
53
|
viewport: 'width=device-width, initial-scale=1, maximum-scale=1',
|
|
54
|
-
}
|
|
55
|
-
}
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
56
|
})
|
|
57
57
|
```
|
|
58
58
|
|
|
@@ -65,12 +65,12 @@ The [`useHead`](/docs/4.x/api/composables/use-head) composable function supports
|
|
|
65
65
|
useHead({
|
|
66
66
|
title: 'My App',
|
|
67
67
|
meta: [
|
|
68
|
-
{ name: 'description', content: 'My amazing site.' }
|
|
68
|
+
{ name: 'description', content: 'My amazing site.' },
|
|
69
69
|
],
|
|
70
70
|
bodyAttrs: {
|
|
71
|
-
class: 'test'
|
|
71
|
+
class: 'test',
|
|
72
72
|
},
|
|
73
|
-
script: [
|
|
73
|
+
script: [{ innerHTML: 'console.log(\'Hello world\')' }],
|
|
74
74
|
})
|
|
75
75
|
</script>
|
|
76
76
|
```
|
|
@@ -118,9 +118,12 @@ const title = ref('Hello World')
|
|
|
118
118
|
<div>
|
|
119
119
|
<Head>
|
|
120
120
|
<Title>{{ title }}</Title>
|
|
121
|
-
<Meta
|
|
121
|
+
<Meta
|
|
122
|
+
name="description"
|
|
123
|
+
:content="title"
|
|
124
|
+
/>
|
|
122
125
|
<Style>
|
|
123
|
-
|
|
126
|
+
body { background-color: green; }
|
|
124
127
|
</Style>
|
|
125
128
|
</Head>
|
|
126
129
|
|
|
@@ -145,9 +148,9 @@ interface MetaObject {
|
|
|
145
148
|
meta?: Meta[]
|
|
146
149
|
style?: Style[]
|
|
147
150
|
script?: Script[]
|
|
148
|
-
noscript?: Noscript[]
|
|
149
|
-
htmlAttrs?: HtmlAttributes
|
|
150
|
-
bodyAttrs?: BodyAttributes
|
|
151
|
+
noscript?: Noscript[]
|
|
152
|
+
htmlAttrs?: HtmlAttributes
|
|
153
|
+
bodyAttrs?: BodyAttributes
|
|
151
154
|
}
|
|
152
155
|
```
|
|
153
156
|
|
|
@@ -167,7 +170,7 @@ Reactivity is supported on all properties, by providing a computed value, a gett
|
|
|
167
170
|
|
|
168
171
|
useHead({
|
|
169
172
|
meta: [
|
|
170
|
-
{ name: 'description', content: description }
|
|
173
|
+
{ name: 'description', content: description },
|
|
171
174
|
],
|
|
172
175
|
})
|
|
173
176
|
</script>
|
|
@@ -178,7 +181,7 @@ Reactivity is supported on all properties, by providing a computed value, a gett
|
|
|
178
181
|
const description = ref('My amazing site.')
|
|
179
182
|
|
|
180
183
|
useSeoMeta({
|
|
181
|
-
description
|
|
184
|
+
description,
|
|
182
185
|
})
|
|
183
186
|
</script>
|
|
184
187
|
```
|
|
@@ -190,7 +193,10 @@ Reactivity is supported on all properties, by providing a computed value, a gett
|
|
|
190
193
|
|
|
191
194
|
<template>
|
|
192
195
|
<div>
|
|
193
|
-
<Meta
|
|
196
|
+
<Meta
|
|
197
|
+
name="description"
|
|
198
|
+
:content="description"
|
|
199
|
+
/>
|
|
194
200
|
</div>
|
|
195
201
|
</template>
|
|
196
202
|
```
|
|
@@ -211,8 +217,8 @@ If you want to use a function (for full control), then this cannot be set in you
|
|
|
211
217
|
<script setup lang="ts">
|
|
212
218
|
useHead({
|
|
213
219
|
titleTemplate: (titleChunk) => {
|
|
214
|
-
return titleChunk ? `${titleChunk} - Site Title` : 'Site Title'
|
|
215
|
-
}
|
|
220
|
+
return titleChunk ? `${titleChunk} - Site Title` : 'Site Title'
|
|
221
|
+
},
|
|
216
222
|
})
|
|
217
223
|
</script>
|
|
218
224
|
```
|
|
@@ -231,12 +237,12 @@ You can use `templateParams` to provide additional placeholders in your `titleTe
|
|
|
231
237
|
<script setup lang="ts">
|
|
232
238
|
useHead({
|
|
233
239
|
titleTemplate: (titleChunk) => {
|
|
234
|
-
return titleChunk ? `${titleChunk} %separator %siteName` : '%siteName'
|
|
240
|
+
return titleChunk ? `${titleChunk} %separator %siteName` : '%siteName'
|
|
235
241
|
},
|
|
236
242
|
templateParams: {
|
|
237
243
|
siteName: 'Site Title',
|
|
238
|
-
separator: '-'
|
|
239
|
-
}
|
|
244
|
+
separator: '-',
|
|
245
|
+
},
|
|
240
246
|
})
|
|
241
247
|
</script>
|
|
242
248
|
```
|
|
@@ -256,9 +262,9 @@ useHead({
|
|
|
256
262
|
{
|
|
257
263
|
src: 'https://third-party-script.com',
|
|
258
264
|
// valid options are: 'head' | 'bodyClose' | 'bodyOpen'
|
|
259
|
-
tagPosition: 'bodyClose'
|
|
260
|
-
}
|
|
261
|
-
]
|
|
265
|
+
tagPosition: 'bodyClose',
|
|
266
|
+
},
|
|
267
|
+
],
|
|
262
268
|
})
|
|
263
269
|
</script>
|
|
264
270
|
```
|
|
@@ -274,7 +280,7 @@ For example, you can first set the current page title (this is extracted at buil
|
|
|
274
280
|
```vue twoslash [pages/some-page.vue]
|
|
275
281
|
<script setup lang="ts">
|
|
276
282
|
definePageMeta({
|
|
277
|
-
title: 'Some Page'
|
|
283
|
+
title: 'Some Page',
|
|
278
284
|
})
|
|
279
285
|
</script>
|
|
280
286
|
```
|
|
@@ -286,7 +292,7 @@ And then in your layout file, you might use the route's metadata you have previo
|
|
|
286
292
|
const route = useRoute()
|
|
287
293
|
|
|
288
294
|
useHead({
|
|
289
|
-
meta: [{ property: 'og:title', content: `App Name - ${route.meta.title}` }]
|
|
295
|
+
meta: [{ property: 'og:title', content: `App Name - ${route.meta.title}` }],
|
|
290
296
|
})
|
|
291
297
|
</script>
|
|
292
298
|
```
|
|
@@ -317,7 +323,7 @@ useHead({
|
|
|
317
323
|
return productCategory
|
|
318
324
|
? `${productCategory} - Site Title`
|
|
319
325
|
: 'Site Title'
|
|
320
|
-
}
|
|
326
|
+
},
|
|
321
327
|
})
|
|
322
328
|
</script>
|
|
323
329
|
```
|
|
@@ -336,14 +342,14 @@ The example below shows how you might enable Google Fonts using either the `link
|
|
|
336
342
|
link: [
|
|
337
343
|
{
|
|
338
344
|
rel: 'preconnect',
|
|
339
|
-
href: 'https://fonts.googleapis.com'
|
|
345
|
+
href: 'https://fonts.googleapis.com',
|
|
340
346
|
},
|
|
341
347
|
{
|
|
342
348
|
rel: 'stylesheet',
|
|
343
349
|
href: 'https://fonts.googleapis.com/css2?family=Roboto&display=swap',
|
|
344
|
-
crossorigin: ''
|
|
345
|
-
}
|
|
346
|
-
]
|
|
350
|
+
crossorigin: '',
|
|
351
|
+
},
|
|
352
|
+
],
|
|
347
353
|
})
|
|
348
354
|
</script>
|
|
349
355
|
```
|
|
@@ -351,8 +357,15 @@ The example below shows how you might enable Google Fonts using either the `link
|
|
|
351
357
|
```vue [app/Components]
|
|
352
358
|
<template>
|
|
353
359
|
<div>
|
|
354
|
-
<Link
|
|
355
|
-
|
|
360
|
+
<Link
|
|
361
|
+
rel="preconnect"
|
|
362
|
+
href="https://fonts.googleapis.com"
|
|
363
|
+
/>
|
|
364
|
+
<Link
|
|
365
|
+
rel="stylesheet"
|
|
366
|
+
href="https://fonts.googleapis.com/css2?family=Roboto&display=swap"
|
|
367
|
+
crossorigin=""
|
|
368
|
+
/>
|
|
356
369
|
</div>
|
|
357
370
|
</template>
|
|
358
371
|
```
|