@nuxt/docs 0.0.0 → 3.17.0
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/.navigation.yml +2 -0
- package/1.getting-started/.navigation.yml +3 -0
- package/1.getting-started/01.introduction.md +81 -0
- package/1.getting-started/02.installation.md +109 -0
- package/1.getting-started/03.configuration.md +226 -0
- package/1.getting-started/04.views.md +163 -0
- package/1.getting-started/05.assets.md +48 -0
- package/1.getting-started/06.styling.md +565 -0
- package/1.getting-started/07.routing.md +149 -0
- package/1.getting-started/08.seo-meta.md +360 -0
- package/1.getting-started/09.transitions.md +473 -0
- package/1.getting-started/10.data-fetching.md +795 -0
- package/1.getting-started/11.state-management.md +223 -0
- package/1.getting-started/12.error-handling.md +233 -0
- package/1.getting-started/13.server.md +94 -0
- package/1.getting-started/14.layers.md +92 -0
- package/1.getting-started/15.prerendering.md +194 -0
- package/1.getting-started/16.deployment.md +130 -0
- package/1.getting-started/17.testing.md +728 -0
- package/1.getting-started/18.upgrade.md +997 -0
- package/2.guide/.navigation.yml +2 -0
- package/2.guide/0.index.md +22 -0
- package/2.guide/1.concepts/.navigation.yml +3 -0
- package/2.guide/1.concepts/1.auto-imports.md +205 -0
- package/2.guide/1.concepts/10.nuxt-lifecycle.md +141 -0
- package/2.guide/1.concepts/2.vuejs-development.md +103 -0
- package/2.guide/1.concepts/3.rendering.md +255 -0
- package/2.guide/1.concepts/4.server-engine.md +62 -0
- package/2.guide/1.concepts/5.modules.md +48 -0
- package/2.guide/1.concepts/7.esm.md +299 -0
- package/2.guide/1.concepts/8.typescript.md +97 -0
- package/2.guide/1.concepts/9.code-style.md +22 -0
- package/2.guide/2.directory-structure/.navigation.yml +3 -0
- package/2.guide/2.directory-structure/0.nuxt.md +20 -0
- package/2.guide/2.directory-structure/0.output.md +18 -0
- package/2.guide/2.directory-structure/1.assets.md +16 -0
- package/2.guide/2.directory-structure/1.components.md +608 -0
- package/2.guide/2.directory-structure/1.composables.md +121 -0
- package/2.guide/2.directory-structure/1.content.md +64 -0
- package/2.guide/2.directory-structure/1.layouts.md +180 -0
- package/2.guide/2.directory-structure/1.middleware.md +209 -0
- package/2.guide/2.directory-structure/1.modules.md +66 -0
- package/2.guide/2.directory-structure/1.node_modules.md +12 -0
- package/2.guide/2.directory-structure/1.pages.md +440 -0
- package/2.guide/2.directory-structure/1.plugins.md +299 -0
- package/2.guide/2.directory-structure/1.public.md +27 -0
- package/2.guide/2.directory-structure/1.server.md +546 -0
- package/2.guide/2.directory-structure/1.shared.md +104 -0
- package/2.guide/2.directory-structure/1.utils.md +49 -0
- package/2.guide/2.directory-structure/2.env.md +75 -0
- package/2.guide/2.directory-structure/2.gitignore.md +37 -0
- package/2.guide/2.directory-structure/2.nuxtignore.md +36 -0
- package/2.guide/2.directory-structure/2.nuxtrc.md +50 -0
- package/2.guide/2.directory-structure/3.app-config.md +177 -0
- package/2.guide/2.directory-structure/3.app.md +72 -0
- package/2.guide/2.directory-structure/3.error.md +55 -0
- package/2.guide/2.directory-structure/3.nuxt-config.md +34 -0
- package/2.guide/2.directory-structure/3.package.md +32 -0
- package/2.guide/2.directory-structure/3.tsconfig.md +24 -0
- package/2.guide/3.going-further/.navigation.yml +3 -0
- package/2.guide/3.going-further/1.experimental-features.md +689 -0
- package/2.guide/3.going-further/1.features.md +103 -0
- package/2.guide/3.going-further/1.internals.md +81 -0
- package/2.guide/3.going-further/10.runtime-config.md +174 -0
- package/2.guide/3.going-further/11.nightly-release-channel.md +68 -0
- package/2.guide/3.going-further/2.hooks.md +98 -0
- package/2.guide/3.going-further/3.modules.md +811 -0
- package/2.guide/3.going-further/4.kit.md +51 -0
- package/2.guide/3.going-further/6.nuxt-app.md +64 -0
- package/2.guide/3.going-further/7.layers.md +227 -0
- package/2.guide/3.going-further/9.debugging.md +115 -0
- package/2.guide/3.going-further/index.md +4 -0
- package/2.guide/4.recipes/.navigation.yml +3 -0
- package/2.guide/4.recipes/1.custom-routing.md +181 -0
- package/2.guide/4.recipes/2.vite-plugin.md +65 -0
- package/2.guide/4.recipes/3.custom-usefetch.md +125 -0
- package/2.guide/4.recipes/4.sessions-and-authentication.md +203 -0
- package/3.api/.navigation.yml +3 -0
- package/3.api/1.components/.navigation.yml +3 -0
- package/3.api/1.components/1.client-only.md +76 -0
- package/3.api/1.components/1.dev-only.md +51 -0
- package/3.api/1.components/1.nuxt-client-fallback.md +80 -0
- package/3.api/1.components/10.nuxt-picture.md +27 -0
- package/3.api/1.components/11.teleports.md +40 -0
- package/3.api/1.components/12.nuxt-route-announcer.md +56 -0
- package/3.api/1.components/13.nuxt-time.md +173 -0
- package/3.api/1.components/2.nuxt-page.md +154 -0
- package/3.api/1.components/3.nuxt-layout.md +156 -0
- package/3.api/1.components/4.nuxt-link.md +322 -0
- package/3.api/1.components/5.nuxt-loading-indicator.md +50 -0
- package/3.api/1.components/6.nuxt-error-boundary.md +65 -0
- package/3.api/1.components/7.nuxt-welcome.md +25 -0
- package/3.api/1.components/8.nuxt-island.md +70 -0
- package/3.api/1.components/9.nuxt-img.md +43 -0
- package/3.api/2.composables/.navigation.yml +3 -0
- package/3.api/2.composables/on-prehydrate.md +60 -0
- package/3.api/2.composables/use-app-config.md +19 -0
- package/3.api/2.composables/use-async-data.md +212 -0
- package/3.api/2.composables/use-cookie.md +233 -0
- package/3.api/2.composables/use-error.md +32 -0
- package/3.api/2.composables/use-fetch.md +217 -0
- package/3.api/2.composables/use-head-safe.md +55 -0
- package/3.api/2.composables/use-head.md +69 -0
- package/3.api/2.composables/use-hydration.md +68 -0
- package/3.api/2.composables/use-lazy-async-data.md +47 -0
- package/3.api/2.composables/use-lazy-fetch.md +55 -0
- package/3.api/2.composables/use-loading-indicator.md +77 -0
- package/3.api/2.composables/use-nuxt-app.md +294 -0
- package/3.api/2.composables/use-nuxt-data.md +112 -0
- package/3.api/2.composables/use-preview-mode.md +118 -0
- package/3.api/2.composables/use-request-event.md +23 -0
- package/3.api/2.composables/use-request-fetch.md +52 -0
- package/3.api/2.composables/use-request-header.md +34 -0
- package/3.api/2.composables/use-request-headers.md +37 -0
- package/3.api/2.composables/use-request-url.md +41 -0
- package/3.api/2.composables/use-response-header.md +48 -0
- package/3.api/2.composables/use-route-announcer.md +60 -0
- package/3.api/2.composables/use-route.md +52 -0
- package/3.api/2.composables/use-router.md +92 -0
- package/3.api/2.composables/use-runtime-config.md +142 -0
- package/3.api/2.composables/use-runtime-hook.md +43 -0
- package/3.api/2.composables/use-seo-meta.md +80 -0
- package/3.api/2.composables/use-server-seo-meta.md +27 -0
- package/3.api/2.composables/use-state.md +48 -0
- package/3.api/3.utils/$fetch.md +98 -0
- package/3.api/3.utils/.navigation.yml +3 -0
- package/3.api/3.utils/abort-navigation.md +73 -0
- package/3.api/3.utils/add-route-middleware.md +88 -0
- package/3.api/3.utils/call-once.md +92 -0
- package/3.api/3.utils/clear-error.md +29 -0
- package/3.api/3.utils/clear-nuxt-data.md +23 -0
- package/3.api/3.utils/clear-nuxt-state.md +23 -0
- package/3.api/3.utils/create-error.md +55 -0
- package/3.api/3.utils/define-nuxt-component.md +53 -0
- package/3.api/3.utils/define-nuxt-route-middleware.md +67 -0
- package/3.api/3.utils/define-page-meta.md +234 -0
- package/3.api/3.utils/define-route-rules.md +52 -0
- package/3.api/3.utils/navigate-to.md +230 -0
- package/3.api/3.utils/on-before-route-leave.md +11 -0
- package/3.api/3.utils/on-before-route-update.md +11 -0
- package/3.api/3.utils/on-nuxt-ready.md +25 -0
- package/3.api/3.utils/prefetch-components.md +28 -0
- package/3.api/3.utils/preload-components.md +23 -0
- package/3.api/3.utils/preload-route-components.md +41 -0
- package/3.api/3.utils/prerender-routes.md +46 -0
- package/3.api/3.utils/refresh-cookie.md +46 -0
- package/3.api/3.utils/refresh-nuxt-data.md +91 -0
- package/3.api/3.utils/reload-nuxt-app.md +74 -0
- package/3.api/3.utils/set-page-layout.md +24 -0
- package/3.api/3.utils/set-response-status.md +36 -0
- package/3.api/3.utils/show-error.md +31 -0
- package/3.api/3.utils/update-app-config.md +27 -0
- package/3.api/4.commands/.navigation.yml +3 -0
- package/3.api/4.commands/add.md +112 -0
- package/3.api/4.commands/analyze.md +41 -0
- package/3.api/4.commands/build-module.md +42 -0
- package/3.api/4.commands/build.md +46 -0
- package/3.api/4.commands/cleanup.md +38 -0
- package/3.api/4.commands/dev.md +59 -0
- package/3.api/4.commands/devtools.md +38 -0
- package/3.api/4.commands/generate.md +41 -0
- package/3.api/4.commands/info.md +33 -0
- package/3.api/4.commands/init.md +46 -0
- package/3.api/4.commands/module.md +84 -0
- package/3.api/4.commands/prepare.md +36 -0
- package/3.api/4.commands/preview.md +43 -0
- package/3.api/4.commands/typecheck.md +42 -0
- package/3.api/4.commands/upgrade.md +37 -0
- package/3.api/5.kit/.navigation.yml +3 -0
- package/3.api/5.kit/1.modules.md +172 -0
- package/3.api/5.kit/10.runtime-config.md +27 -0
- package/3.api/5.kit/10.templates.md +283 -0
- package/3.api/5.kit/11.nitro.md +409 -0
- package/3.api/5.kit/12.resolving.md +268 -0
- package/3.api/5.kit/13.logging.md +65 -0
- package/3.api/5.kit/14.builder.md +491 -0
- package/3.api/5.kit/15.examples.md +41 -0
- package/3.api/5.kit/2.programmatic.md +125 -0
- package/3.api/5.kit/3.compatibility.md +230 -0
- package/3.api/5.kit/4.autoimports.md +144 -0
- package/3.api/5.kit/5.components.md +127 -0
- package/3.api/5.kit/6.context.md +130 -0
- package/3.api/5.kit/7.pages.md +295 -0
- package/3.api/5.kit/8.layout.md +80 -0
- package/3.api/5.kit/9.plugins.md +263 -0
- package/3.api/6.advanced/.navigation.yml +1 -0
- package/3.api/6.advanced/1.hooks.md +105 -0
- package/3.api/6.advanced/2.import-meta.md +60 -0
- package/3.api/6.nuxt-config.md +12 -0
- package/3.api/index.md +31 -0
- package/5.community/.navigation.yml +3 -0
- package/5.community/2.getting-help.md +48 -0
- package/5.community/3.reporting-bugs.md +50 -0
- package/5.community/4.contribution.md +205 -0
- package/5.community/5.framework-contribution.md +142 -0
- package/5.community/6.roadmap.md +79 -0
- package/5.community/7.changelog.md +92 -0
- package/6.bridge/.navigation.yml +3 -0
- package/6.bridge/1.overview.md +137 -0
- package/6.bridge/10.configuration.md +96 -0
- package/6.bridge/2.typescript.md +46 -0
- package/6.bridge/3.bridge-composition-api.md +132 -0
- package/6.bridge/4.plugins-and-middleware.md +65 -0
- package/6.bridge/5.nuxt3-compatible-api.md +204 -0
- package/6.bridge/6.meta.md +117 -0
- package/6.bridge/7.runtime-config.md +38 -0
- package/6.bridge/8.nitro.md +102 -0
- package/6.bridge/9.vite.md +37 -0
- package/7.migration/.navigation.yml +3 -0
- package/7.migration/1.overview.md +24 -0
- package/7.migration/10.bundling.md +28 -0
- package/7.migration/11.server.md +17 -0
- package/7.migration/2.configuration.md +240 -0
- package/7.migration/20.module-authors.md +94 -0
- package/7.migration/3.auto-imports.md +18 -0
- package/7.migration/4.meta.md +127 -0
- package/7.migration/5.plugins-and-middleware.md +80 -0
- package/7.migration/6.pages-and-layouts.md +233 -0
- package/7.migration/7.component-options.md +156 -0
- package/7.migration/8.runtime-config.md +58 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/package.json +16 -4
- package/dist/.gitkeep +0 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "<NuxtLink>"
|
|
3
|
+
description: "Nuxt provides <NuxtLink> component to handle any kind of links within your application."
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/nuxt-link.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
::note
|
|
12
|
+
`<NuxtLink>` is a drop-in replacement for both Vue Router's `<RouterLink>` component and HTML's `<a>` tag. It intelligently determines whether the link is _internal_ or _external_ and renders it accordingly with available optimizations (prefetching, default attributes, etc.)
|
|
13
|
+
::
|
|
14
|
+
|
|
15
|
+
## Internal Routing
|
|
16
|
+
|
|
17
|
+
In this example, we use `<NuxtLink>` component to link to another page of the application.
|
|
18
|
+
|
|
19
|
+
::code-group
|
|
20
|
+
```vue [pages/index.vue]
|
|
21
|
+
<template>
|
|
22
|
+
<NuxtLink to="/about">About page</NuxtLink>
|
|
23
|
+
</template>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```html [(Renders as) index.html]
|
|
27
|
+
<!-- (Vue Router & Smart Prefetching) -->
|
|
28
|
+
<a href="/about">About page</a>
|
|
29
|
+
```
|
|
30
|
+
::
|
|
31
|
+
|
|
32
|
+
### Passing Params to Dynamic Routes
|
|
33
|
+
|
|
34
|
+
In this example, we pass the `id` param to link to the route `~/pages/posts/[id].vue`.
|
|
35
|
+
|
|
36
|
+
::code-group
|
|
37
|
+
```vue [pages/index.vue]
|
|
38
|
+
<template>
|
|
39
|
+
<NuxtLink :to="{ name: 'posts-id', params: { id: 123 } }">
|
|
40
|
+
Post 123
|
|
41
|
+
</NuxtLink>
|
|
42
|
+
</template>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```html [(Renders as) index.html]
|
|
46
|
+
<a href="/posts/123">Post 123</a>
|
|
47
|
+
```
|
|
48
|
+
::
|
|
49
|
+
|
|
50
|
+
::tip
|
|
51
|
+
Check out the Pages panel in Nuxt DevTools to see the route name and the params it might take.
|
|
52
|
+
::
|
|
53
|
+
|
|
54
|
+
### Handling Static File and Cross-App Links
|
|
55
|
+
|
|
56
|
+
By default, `<NuxtLink>` uses Vue Router's client side navigation for relative route. When linking to static files in the `/public` directory or to another application hosted on the same domain, it might result in unexpected 404 errors because they are not part of the client routes. In such cases, you can use the `external` prop with `<NuxtLink>` to bypass Vue Router's internal routing mechanism.
|
|
57
|
+
|
|
58
|
+
The `external` prop explicitly indicates that the link is external. `<NuxtLink>` will render the link as a standard HTML `<a>` tag. This ensures the link behaves correctly, bypassing Vue Router’s logic and directly pointing to the resource.
|
|
59
|
+
|
|
60
|
+
#### Linking to Static Files
|
|
61
|
+
|
|
62
|
+
For static files in the `/public` directory, such as PDFs or images, use the `external` prop to ensure the link resolves correctly.
|
|
63
|
+
|
|
64
|
+
```vue [pages/index.vue]
|
|
65
|
+
<template>
|
|
66
|
+
<NuxtLink to="/example-report.pdf" external>
|
|
67
|
+
Download Report
|
|
68
|
+
</NuxtLink>
|
|
69
|
+
</template>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### Linking to a Cross-App URL
|
|
73
|
+
|
|
74
|
+
When pointing to a different application on the same domain, using the `external` prop ensures the correct behavior.
|
|
75
|
+
|
|
76
|
+
```vue [pages/index.vue]
|
|
77
|
+
<template>
|
|
78
|
+
<NuxtLink to="/another-app" external>
|
|
79
|
+
Go to Another App
|
|
80
|
+
</NuxtLink>
|
|
81
|
+
</template>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Using the `external` prop or relying on automatic handling ensures proper navigation, avoids unexpected routing issues, and improves compatibility with static resources or cross-application scenarios.
|
|
85
|
+
|
|
86
|
+
## External Routing
|
|
87
|
+
|
|
88
|
+
In this example, we use `<NuxtLink>` component to link to a website.
|
|
89
|
+
|
|
90
|
+
```vue [app.vue]
|
|
91
|
+
<template>
|
|
92
|
+
<NuxtLink to="https://nuxtjs.org">
|
|
93
|
+
Nuxt website
|
|
94
|
+
</NuxtLink>
|
|
95
|
+
<!-- <a href="https://nuxtjs.org" rel="noopener noreferrer">...</a> -->
|
|
96
|
+
</template>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## `rel` and `noRel` Attributes
|
|
100
|
+
|
|
101
|
+
A `rel` attribute of `noopener noreferrer` is applied by default to links with a `target` attribute or to absolute links (e.g., links starting with `http://`, `https://`, or `//`).
|
|
102
|
+
- `noopener` solves a [security bug](https://mathiasbynens.github.io/rel-noopener/) in older browsers.
|
|
103
|
+
- `noreferrer` improves privacy for your users by not sending the `Referer` header to the linked site.
|
|
104
|
+
|
|
105
|
+
These defaults have no negative impact on SEO and are considered [best practice](https://developer.chrome.com/docs/lighthouse/best-practices/external-anchors-use-rel-noopener).
|
|
106
|
+
|
|
107
|
+
When you need to overwrite this behavior you can use the `rel` or `noRel` props.
|
|
108
|
+
|
|
109
|
+
```vue [app.vue]
|
|
110
|
+
<template>
|
|
111
|
+
<NuxtLink to="https://twitter.com/nuxt_js">
|
|
112
|
+
Nuxt Twitter
|
|
113
|
+
</NuxtLink>
|
|
114
|
+
<!-- <a href="https://twitter.com/nuxt_js" rel="noopener noreferrer">...</a> -->
|
|
115
|
+
|
|
116
|
+
<NuxtLink to="https://discord.nuxtjs.org" rel="noopener">
|
|
117
|
+
Nuxt Discord
|
|
118
|
+
</NuxtLink>
|
|
119
|
+
<!-- <a href="https://discord.nuxtjs.org" rel="noopener">...</a> -->
|
|
120
|
+
|
|
121
|
+
<NuxtLink to="/about" target="_blank">About page</NuxtLink>
|
|
122
|
+
<!-- <a href="/about" target="_blank" rel="noopener noreferrer">...</a> -->
|
|
123
|
+
</template>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
A `noRel` prop can be used to prevent the default `rel` attribute from being added to the absolute links.
|
|
127
|
+
|
|
128
|
+
```vue [app.vue]
|
|
129
|
+
<template>
|
|
130
|
+
<NuxtLink to="https://github.com/nuxt" no-rel>
|
|
131
|
+
Nuxt GitHub
|
|
132
|
+
</NuxtLink>
|
|
133
|
+
<!-- <a href="https://github.com/nuxt">...</a> -->
|
|
134
|
+
</template>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
::note
|
|
138
|
+
`noRel` and `rel` cannot be used together. `rel` will be ignored.
|
|
139
|
+
::
|
|
140
|
+
|
|
141
|
+
## Prefetch Links
|
|
142
|
+
|
|
143
|
+
Nuxt automatically includes smart prefetching. That means it detects when a link is visible (by default), either in the viewport or when scrolling and prefetches the JavaScript for those pages so that they are ready when the user clicks the link. Nuxt only loads the resources when the browser isn't busy and skips prefetching if your connection is offline or if you only have 2g connection.
|
|
144
|
+
|
|
145
|
+
```vue [pages/index.vue]
|
|
146
|
+
<NuxtLink to="/about" no-prefetch>About page not pre-fetched</NuxtLink>
|
|
147
|
+
<NuxtLink to="/about" :prefetch="false">About page not pre-fetched</NuxtLink>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Custom Prefetch Triggers
|
|
151
|
+
|
|
152
|
+
We now support custom prefetch triggers for `<NuxtLink>` after `v3.13.0`. You can use the `prefetchOn` prop to control when to prefetch links.
|
|
153
|
+
|
|
154
|
+
```vue
|
|
155
|
+
<template>
|
|
156
|
+
<NuxtLink prefetch-on="visibility">
|
|
157
|
+
This will prefetch when it becomes visible (default)
|
|
158
|
+
</NuxtLink>
|
|
159
|
+
|
|
160
|
+
<NuxtLink prefetch-on="interaction">
|
|
161
|
+
This will prefetch when hovered or when it gains focus
|
|
162
|
+
</NuxtLink>
|
|
163
|
+
</template>
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
- `visibility`: Prefetches when the link becomes visible in the viewport. Monitors the element's intersection with the viewport using the [Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API). Prefetching is triggered when the element is scrolled into view.
|
|
167
|
+
- `interaction`: Prefetches when the link is hovered or focused. This approach listens for `pointerenter` and `focus` events, proactively prefetching resources when the user indicates intent to interact.
|
|
168
|
+
|
|
169
|
+
You can also use an object to configure `prefetchOn`:
|
|
170
|
+
|
|
171
|
+
```vue
|
|
172
|
+
<template>
|
|
173
|
+
<NuxtLink :prefetch-on="{ interaction: true }">
|
|
174
|
+
This will prefetch when hovered or when it gains focus
|
|
175
|
+
</NuxtLink>
|
|
176
|
+
</template>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
That you probably don't want both enabled!
|
|
180
|
+
|
|
181
|
+
```vue
|
|
182
|
+
<template>
|
|
183
|
+
<NuxtLink :prefetch-on="{ visibility: true, interaction: true }">
|
|
184
|
+
This will prefetch when hovered/focus - or when it becomes visible
|
|
185
|
+
</NuxtLink>
|
|
186
|
+
</template>
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
This configuration will observe when the element enters the viewport and also listen for `pointerenter` and `focus` events. This may result in unnecessary resource usage or redundant prefetching, as both triggers can prefetch the same resource under different conditions.
|
|
190
|
+
|
|
191
|
+
### Enable Cross-origin Prefetch
|
|
192
|
+
|
|
193
|
+
To enable cross-origin prefetching, you can set the `crossOriginPrefetch` option in your `nuxt.config`. This will enable cross-origin prefetching using the [Speculation Rules API](https://developer.mozilla.org/en-US/docs/Web/API/Speculation_Rules_API).
|
|
194
|
+
|
|
195
|
+
```ts [nuxt.config.ts]
|
|
196
|
+
export default defineNuxtConfig({
|
|
197
|
+
experimental: {
|
|
198
|
+
crossOriginPrefetch: true,
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Disable prefetch globally
|
|
204
|
+
|
|
205
|
+
It's also possible to enable/disable prefetching all links globally for your app.
|
|
206
|
+
|
|
207
|
+
```ts [nuxt.config.ts]
|
|
208
|
+
export default defineNuxtConfig({
|
|
209
|
+
experimental: {
|
|
210
|
+
defaults: {
|
|
211
|
+
nuxtLink: {
|
|
212
|
+
prefetch: false,
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
})
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Props
|
|
220
|
+
|
|
221
|
+
### RouterLink
|
|
222
|
+
|
|
223
|
+
When not using `external`, `<NuxtLink>` supports all Vue Router's [`RouterLink` props](https://router.vuejs.org/api/interfaces/RouterLinkProps.html)
|
|
224
|
+
|
|
225
|
+
- `to`: Any URL or a [route location object](https://router.vuejs.org/api/#RouteLocation) from Vue Router
|
|
226
|
+
- `custom`: Whether `<NuxtLink>` should wrap its content in an `<a>` element. It allows taking full control of how a link is rendered and how navigation works when it is clicked. Works the same as [Vue Router's `custom` prop](https://router.vuejs.org/api/interfaces/RouterLinkProps.html#Properties-custom)
|
|
227
|
+
- `exactActiveClass`: A class to apply on exact active links. Works the same as [Vue Router's `exactActiveClass` prop](https://router.vuejs.org/api/interfaces/RouterLinkProps.html#Properties-exactActiveClass) on internal links. Defaults to Vue Router's default (`"router-link-exact-active"`)
|
|
228
|
+
- `activeClass`: A class to apply on active links. Works the same as [Vue Router's `activeClass` prop](https://router.vuejs.org/api/interfaces/RouterLinkProps.html#Properties-activeClass) on internal links. Defaults to Vue Router's default (`"router-link-active"`)
|
|
229
|
+
- `replace`: Works the same as [Vue Router's `replace` prop](https://router.vuejs.org/api/interfaces/RouteLocationOptions.html#Properties-replace) on internal links
|
|
230
|
+
- `ariaCurrentValue`: An `aria-current` attribute value to apply on exact active links. Works the same as [Vue Router's `ariaCurrentValue` prop](https://router.vuejs.org/api/interfaces/RouterLinkProps.html#Properties-ariaCurrentValue) on internal links
|
|
231
|
+
|
|
232
|
+
### NuxtLink
|
|
233
|
+
|
|
234
|
+
- `href`: An alias for `to`. If used with `to`, `href` will be ignored
|
|
235
|
+
- `noRel`: If set to `true`, no `rel` attribute will be added to the external link
|
|
236
|
+
- `external`: Forces the link to be rendered as an `<a>` tag instead of a Vue Router `RouterLink`.
|
|
237
|
+
- `prefetch`: When enabled will prefetch middleware, layouts and payloads (when using [payloadExtraction](/docs/api/nuxt-config#crossoriginprefetch)) of links in the viewport. Used by the experimental [crossOriginPrefetch](/docs/api/nuxt-config#crossoriginprefetch) config.
|
|
238
|
+
- `prefetchOn`: Allows custom control of when to prefetch links. Possible options are `interaction` and `visibility` (default). You can also pass an object for full control, for example: `{ interaction: true, visibility: true }`. This prop is only used when `prefetch` is enabled (default) and `noPrefetch` is not set.
|
|
239
|
+
- `noPrefetch`: Disables prefetching.
|
|
240
|
+
- `prefetchedClass`: A class to apply to links that have been prefetched.
|
|
241
|
+
|
|
242
|
+
### Anchor
|
|
243
|
+
|
|
244
|
+
- `target`: A `target` attribute value to apply on the link
|
|
245
|
+
- `rel`: A `rel` attribute value to apply on the link. Defaults to `"noopener noreferrer"` for external links.
|
|
246
|
+
|
|
247
|
+
::tip
|
|
248
|
+
Defaults can be overwritten, see [overwriting defaults](#overwriting-defaults) if you want to change them.
|
|
249
|
+
::
|
|
250
|
+
|
|
251
|
+
## Overwriting Defaults
|
|
252
|
+
|
|
253
|
+
### In Nuxt Config
|
|
254
|
+
|
|
255
|
+
You can overwrite some `<NuxtLink>` defaults in your [`nuxt.config`](/docs/api/nuxt-config#defaults)
|
|
256
|
+
|
|
257
|
+
::important
|
|
258
|
+
These options will likely be moved elsewhere in the future, such as into `app.config` or into the `app/` directory.
|
|
259
|
+
::
|
|
260
|
+
|
|
261
|
+
```ts [nuxt.config.ts]
|
|
262
|
+
export default defineNuxtConfig({
|
|
263
|
+
experimental: {
|
|
264
|
+
defaults: {
|
|
265
|
+
nuxtLink: {
|
|
266
|
+
// default values
|
|
267
|
+
componentName: 'NuxtLink',
|
|
268
|
+
externalRelAttribute: 'noopener noreferrer',
|
|
269
|
+
activeClass: 'router-link-active',
|
|
270
|
+
exactActiveClass: 'router-link-exact-active',
|
|
271
|
+
prefetchedClass: undefined, // can be any valid string class name
|
|
272
|
+
trailingSlash: undefined // can be 'append' or 'remove'
|
|
273
|
+
prefetch: true,
|
|
274
|
+
prefetchOn: { visibility: true }
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
})
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Custom Link Component
|
|
282
|
+
|
|
283
|
+
You can overwrite `<NuxtLink>` defaults by creating your own link component using `defineNuxtLink`.
|
|
284
|
+
|
|
285
|
+
```js [components/MyNuxtLink.ts]
|
|
286
|
+
export default defineNuxtLink({
|
|
287
|
+
componentName: 'MyNuxtLink',
|
|
288
|
+
/* see signature below for more */
|
|
289
|
+
})
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
You can then use `<MyNuxtLink />` component as usual with your new defaults.
|
|
293
|
+
|
|
294
|
+
### `defineNuxtLink` Signature
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
interface NuxtLinkOptions {
|
|
298
|
+
componentName?: string;
|
|
299
|
+
externalRelAttribute?: string;
|
|
300
|
+
activeClass?: string;
|
|
301
|
+
exactActiveClass?: string;
|
|
302
|
+
trailingSlash?: 'append' | 'remove'
|
|
303
|
+
prefetch?: boolean
|
|
304
|
+
prefetchedClass?: string
|
|
305
|
+
prefetchOn?: Partial<{
|
|
306
|
+
visibility: boolean
|
|
307
|
+
interaction: boolean
|
|
308
|
+
}>
|
|
309
|
+
}
|
|
310
|
+
function defineNuxtLink(options: NuxtLinkOptions): Component {}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
- `componentName`: A name for the component. Default is `NuxtLink`.
|
|
314
|
+
- `externalRelAttribute`: A default `rel` attribute value applied on external links. Defaults to `"noopener noreferrer"`. Set it to `""` to disable
|
|
315
|
+
- `activeClass`: A default class to apply on active links. Works the same as [Vue Router's `linkActiveClass` option](https://router.vuejs.org/api/interfaces/RouterOptions.html#Properties-linkActiveClass). Defaults to Vue Router's default (`"router-link-active"`)
|
|
316
|
+
- `exactActiveClass`: A default class to apply on exact active links. Works the same as [Vue Router's `linkExactActiveClass` option](https://router.vuejs.org/api/interfaces/RouterOptions.html#Properties-linkExactActiveClass). Defaults to Vue Router's default (`"router-link-exact-active"`)
|
|
317
|
+
- `trailingSlash`: An option to either add or remove trailing slashes in the `href`. If unset or not matching the valid values `append` or `remove`, it will be ignored.
|
|
318
|
+
- `prefetch`: Whether or not to prefetch links by default.
|
|
319
|
+
- `prefetchOn`: Granular control of which prefetch strategies to apply by default.
|
|
320
|
+
- `prefetchedClass`: A default class to apply to links that have been prefetched.
|
|
321
|
+
|
|
322
|
+
:link-example{to="/docs/examples/routing/pages"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: '<NuxtLoadingIndicator>'
|
|
3
|
+
description: 'Display a progress bar between page navigations.'
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/nuxt-loading-indicator.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Add `<NuxtLoadingIndicator/>` in your [`app.vue`](/docs/guide/directory-structure/app) or [`layouts/`](/docs/guide/directory-structure/layouts).
|
|
14
|
+
|
|
15
|
+
```vue [app.vue]
|
|
16
|
+
<template>
|
|
17
|
+
<NuxtLoadingIndicator />
|
|
18
|
+
<NuxtLayout>
|
|
19
|
+
<NuxtPage />
|
|
20
|
+
</NuxtLayout>
|
|
21
|
+
</template>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
:link-example{to="/docs/examples/routing/pages"}
|
|
25
|
+
|
|
26
|
+
## Slots
|
|
27
|
+
|
|
28
|
+
You can pass custom HTML or components through the loading indicator's default slot.
|
|
29
|
+
|
|
30
|
+
## Props
|
|
31
|
+
|
|
32
|
+
- `color`: The color of the loading bar. It can be set to `false` to turn off explicit color styling.
|
|
33
|
+
- `errorColor`: The color of the loading bar when `error` is set to `true`.
|
|
34
|
+
- `height`: Height of the loading bar, in pixels (default `3`).
|
|
35
|
+
- `duration`: Duration of the loading bar, in milliseconds (default `2000`).
|
|
36
|
+
- `throttle`: Throttle the appearing and hiding, in milliseconds (default `200`).
|
|
37
|
+
- `estimatedProgress`: By default Nuxt will back off as it approaches 100%. You can provide a custom function to customize the progress estimation, which is a function that receives the duration of the loading bar (above) and the elapsed time. It should return a value between 0 and 100.
|
|
38
|
+
|
|
39
|
+
::note
|
|
40
|
+
This component is optional. :br
|
|
41
|
+
To achieve full customization, you can implement your own one based on [its source code](https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/nuxt-loading-indicator.ts).
|
|
42
|
+
::
|
|
43
|
+
|
|
44
|
+
::note
|
|
45
|
+
You can hook into the underlying indicator instance using [the `useLoadingIndicator` composable](/docs/api/composables/use-loading-indicator), which will allow you to trigger start/finish events yourself.
|
|
46
|
+
::
|
|
47
|
+
|
|
48
|
+
::tip
|
|
49
|
+
The loading indicator's speed gradually decreases after reaching a specific point controlled by `estimatedProgress`. This adjustment provides a more accurate reflection of longer page loading times and prevents the indicator from prematurely showing 100% completion.
|
|
50
|
+
::
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "<NuxtErrorBoundary>"
|
|
3
|
+
description: The <NuxtErrorBoundary> component handles client-side errors happening in its default slot.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/nuxt-error-boundary.vue
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
::tip
|
|
12
|
+
The `<NuxtErrorBoundary>` uses Vue's [`onErrorCaptured`](https://vuejs.org/api/composition-api-lifecycle.html#onerrorcaptured) hook under the hood.
|
|
13
|
+
::
|
|
14
|
+
|
|
15
|
+
## Events
|
|
16
|
+
|
|
17
|
+
- `@error`: Event emitted when the default slot of the component throws an error.
|
|
18
|
+
|
|
19
|
+
```vue
|
|
20
|
+
<template>
|
|
21
|
+
<NuxtErrorBoundary @error="logSomeError">
|
|
22
|
+
<!-- ... -->
|
|
23
|
+
</NuxtErrorBoundary>
|
|
24
|
+
</template>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Slots
|
|
28
|
+
|
|
29
|
+
- `#error`: Specify a fallback content to display in case of error.
|
|
30
|
+
|
|
31
|
+
```vue
|
|
32
|
+
<template>
|
|
33
|
+
<NuxtErrorBoundary>
|
|
34
|
+
<!-- ... -->
|
|
35
|
+
<template #error="{ error, clearError }">
|
|
36
|
+
<p>An error occurred: {{ error }}</p>
|
|
37
|
+
|
|
38
|
+
<button @click="clearError">Clear error</button>
|
|
39
|
+
</template>
|
|
40
|
+
</NuxtErrorBoundary>
|
|
41
|
+
</template>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
:read-more{to="/docs/getting-started/error-handling"}
|
|
45
|
+
|
|
46
|
+
## Examples
|
|
47
|
+
|
|
48
|
+
### Accessing `error` and `clearError` in script
|
|
49
|
+
|
|
50
|
+
You can access `error` and `clearError` properties within the component's script as below:
|
|
51
|
+
|
|
52
|
+
```vue
|
|
53
|
+
<template>
|
|
54
|
+
<NuxtErrorBoundary ref="errorBoundary">
|
|
55
|
+
<!-- ... -->
|
|
56
|
+
</NuxtErrorBoundary>
|
|
57
|
+
</template>
|
|
58
|
+
|
|
59
|
+
<script setup lang="ts">
|
|
60
|
+
const errorBoundary = useTemplateRef('errorBoundary')
|
|
61
|
+
|
|
62
|
+
// errorBoundary.value?.error
|
|
63
|
+
// errorBoundary.value?.clearError()
|
|
64
|
+
</script>
|
|
65
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: '<NuxtWelcome>'
|
|
3
|
+
description: The <NuxtWelcome> component greets users in new projects made from the starter template.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/assets/blob/main/packages/templates/templates/welcome/index.html
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
It includes links to the Nuxt documentation, source code, and social media accounts.
|
|
12
|
+
|
|
13
|
+
```vue [app.vue]
|
|
14
|
+
<template>
|
|
15
|
+
<NuxtWelcome />
|
|
16
|
+
</template>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
::read-more{to="https://templates.ui.nuxtjs.org/templates/welcome" target="_blank"}
|
|
20
|
+
Preview the `<NuxtWelcome />` component.
|
|
21
|
+
::
|
|
22
|
+
|
|
23
|
+
::tip
|
|
24
|
+
This component is part of [nuxt/assets](https://github.com/nuxt/assets).
|
|
25
|
+
::
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "<NuxtIsland>"
|
|
3
|
+
description: "Nuxt provides the <NuxtIsland> component to render a non-interactive component without any client JS."
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/nuxt-island.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
When rendering an island component, the content of the island component is static, thus no JS is downloaded client-side.
|
|
12
|
+
|
|
13
|
+
Changing the island component props triggers a refetch of the island component to re-render it again.
|
|
14
|
+
|
|
15
|
+
::note
|
|
16
|
+
Global styles of your application are sent with the response.
|
|
17
|
+
::
|
|
18
|
+
|
|
19
|
+
::tip
|
|
20
|
+
Server only components use `<NuxtIsland>` under the hood
|
|
21
|
+
::
|
|
22
|
+
|
|
23
|
+
## Props
|
|
24
|
+
|
|
25
|
+
- `name` : Name of the component to render.
|
|
26
|
+
- **type**: `string`
|
|
27
|
+
- **required**
|
|
28
|
+
- `lazy`: Make the component non-blocking.
|
|
29
|
+
- **type**: `boolean`
|
|
30
|
+
- **default**: `false`
|
|
31
|
+
- `props`: Props to send to the component to render.
|
|
32
|
+
- **type**: `Record<string, any>`
|
|
33
|
+
- `source`: Remote source to call the island to render.
|
|
34
|
+
- **type**: `string`
|
|
35
|
+
- **dangerouslyLoadClientComponents**: Required to load components from a remote source.
|
|
36
|
+
- **type**: `boolean`
|
|
37
|
+
- **default**: `false`
|
|
38
|
+
|
|
39
|
+
::note
|
|
40
|
+
Remote islands need `experimental.componentIslands` to be `'local+remote'` in your `nuxt.config`.
|
|
41
|
+
It is strongly discouraged to enable `dangerouslyLoadClientComponents` as you can't trust a remote server's javascript.
|
|
42
|
+
::
|
|
43
|
+
|
|
44
|
+
::note
|
|
45
|
+
By default, component islands are scanned from the `~/components/islands/` directory. So the `~/components/islands/MyIsland.vue` component could be rendered with `<NuxtIsland name="MyIsland" />`.
|
|
46
|
+
::
|
|
47
|
+
|
|
48
|
+
## Slots
|
|
49
|
+
|
|
50
|
+
Slots can be passed to an island component if declared.
|
|
51
|
+
|
|
52
|
+
Every slot is interactive since the parent component is the one providing it.
|
|
53
|
+
|
|
54
|
+
Some slots are reserved to `NuxtIsland` for special cases.
|
|
55
|
+
|
|
56
|
+
- `#fallback`: Specify the content to be rendered before the island loads (if the component is lazy) or if `NuxtIsland` fails to fetch the component.
|
|
57
|
+
|
|
58
|
+
## Ref
|
|
59
|
+
|
|
60
|
+
- `refresh()`
|
|
61
|
+
- **type**: `() => Promise<void>`
|
|
62
|
+
- **description**: force refetch the server component by refetching it.
|
|
63
|
+
|
|
64
|
+
## Events
|
|
65
|
+
|
|
66
|
+
- `error`
|
|
67
|
+
- **parameters**:
|
|
68
|
+
- **error**:
|
|
69
|
+
- **type**: `unknown`
|
|
70
|
+
- **description**: emitted when when `NuxtIsland` fails to fetch the new island.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "<NuxtImg>"
|
|
3
|
+
description: "Nuxt provides a <NuxtImg> component to handle automatic image optimization."
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/image/blob/main/src/runtime/components/NuxtImg.vue
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`<NuxtImg>` is a drop-in replacement for the native `<img>` tag.
|
|
12
|
+
|
|
13
|
+
- Uses built-in provider to optimize local and remote images
|
|
14
|
+
- Converts `src` to provider-optimized URLs
|
|
15
|
+
- Automatically resizes images based on `width` and `height`
|
|
16
|
+
- Generates responsive sizes when providing `sizes` option
|
|
17
|
+
- Supports native lazy loading as well as other `<img>` attributes
|
|
18
|
+
|
|
19
|
+
## Setup
|
|
20
|
+
|
|
21
|
+
In order to use `<NuxtImg>` you should install and enable the Nuxt Image module:
|
|
22
|
+
|
|
23
|
+
```bash [Terminal]
|
|
24
|
+
npx nuxi@latest module add image
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
`<NuxtImg>` outputs a native `img` tag directly (without any wrapper around it). Use it like you would use the `<img>` tag:
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<NuxtImg src="/nuxt-icon.png" />
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Will result in:
|
|
36
|
+
|
|
37
|
+
```html
|
|
38
|
+
<img src="/nuxt-icon.png" />
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
::read-more{to="https://image.nuxt.com/usage/nuxt-img" target="_blank"}
|
|
42
|
+
Read more about the `<NuxtImg>` component.
|
|
43
|
+
::
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "onPrehydrate"
|
|
3
|
+
description: "Use onPrehydrate to run a callback on the client immediately before Nuxt hydrates the page."
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/ssr.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
::important
|
|
12
|
+
This composable is available in Nuxt v3.12+.
|
|
13
|
+
::
|
|
14
|
+
|
|
15
|
+
`onPrehydrate` is a composable lifecycle hook that allows you to run a callback on the client immediately before
|
|
16
|
+
Nuxt hydrates the page.
|
|
17
|
+
|
|
18
|
+
::note
|
|
19
|
+
This is an advanced utility and should be used with care. For example, [`nuxt-time`](https://github.com/danielroe/nuxt-time/pull/251) and [`@nuxtjs/color-mode`](https://github.com/nuxt-modules/color-mode/blob/main/src/script.js) manipulate the DOM to avoid hydration mismatches.
|
|
20
|
+
::
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
`onPrehydrate` can be called directly in the setup function of a Vue component (for example, in `<script setup>`), or in a plugin.
|
|
25
|
+
It will only have an effect when it is called on the server, and it will not be included in your client build.
|
|
26
|
+
|
|
27
|
+
## Parameters
|
|
28
|
+
|
|
29
|
+
- `callback`: A function that will be stringified and inlined in the HTML. It should not have any external
|
|
30
|
+
dependencies (such as auto-imports) or refer to variables defined outside the callback. The callback will run
|
|
31
|
+
before Nuxt runtime initializes so it should not rely on the Nuxt or Vue context.
|
|
32
|
+
|
|
33
|
+
## Example
|
|
34
|
+
|
|
35
|
+
```vue twoslash [app.vue]
|
|
36
|
+
<script setup lang="ts">
|
|
37
|
+
declare const window: Window
|
|
38
|
+
// ---cut---
|
|
39
|
+
// onPrehydrate is guaranteed to run before Nuxt hydrates
|
|
40
|
+
onPrehydrate(() => {
|
|
41
|
+
console.log(window)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
// As long as it only has one root node, you can access the element
|
|
45
|
+
onPrehydrate((el) => {
|
|
46
|
+
console.log(el.outerHTML)
|
|
47
|
+
// <div data-v-inspector="app.vue:15:3" data-prehydrate-id=":b3qlvSiBeH:"> Hi there </div>
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
// For _very_ advanced use cases (such as not having a single root node) you
|
|
51
|
+
// can access/set `data-prehydrate-id` yourself
|
|
52
|
+
const prehydrateId = onPrehydrate((el) => {})
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<template>
|
|
56
|
+
<div>
|
|
57
|
+
Hi there
|
|
58
|
+
</div>
|
|
59
|
+
</template>
|
|
60
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'useAppConfig'
|
|
3
|
+
description: 'Access the reactive app config defined in the project.'
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/config.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
const appConfig = useAppConfig()
|
|
15
|
+
|
|
16
|
+
console.log(appConfig)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
:read-more{to="/docs/guide/directory-structure/app-config"}
|