@nuxt/docs-nightly 4.4.0-29533707.0a5a5c19 → 4.4.0-29533984.c5133a48
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.
|
@@ -59,6 +59,7 @@ export default defineNuxtConfig({
|
|
|
59
59
|
When you set your `future.compatibilityVersion` to `5`, defaults throughout your Nuxt configuration will change to opt in to Nuxt v5 behavior, including:
|
|
60
60
|
|
|
61
61
|
- **Vite Environment API**: Automatically enables the new [Vite Environment API](/docs/4.x/getting-started/upgrade#migration-to-vite-environment-api) for improved build configuration
|
|
62
|
+
- **Normalized Page Names**: Page component names will [match their route names](/docs/4.x/getting-started/upgrade#normalized-page-component-names) for consistent `<KeepAlive>` behavior
|
|
62
63
|
- **`clearNuxtState` resets to defaults**: `clearNuxtState` will [reset state to its initial value](/docs/4.x/getting-started/upgrade#respect-defaults-when-clearing-usestate) instead of setting it to `undefined`
|
|
63
64
|
- Other Nuxt 5 improvements and changes as they become available
|
|
64
65
|
|
|
@@ -1374,6 +1375,41 @@ export default defineNuxtConfig({
|
|
|
1374
1375
|
Read more about Nitro's prerender configuration options.
|
|
1375
1376
|
::
|
|
1376
1377
|
|
|
1378
|
+
### Normalized Page Component Names
|
|
1379
|
+
|
|
1380
|
+
🚦 **Impact Level**: Minimal
|
|
1381
|
+
|
|
1382
|
+
#### What Changed
|
|
1383
|
+
|
|
1384
|
+
When `future.compatibilityVersion` is set to `5` (or `experimental.normalizePageNames` is enabled), page component names match their route names instead of using the filename. For example, `pages/foo/index.vue` will have the component name `foo` instead of `index`.
|
|
1385
|
+
|
|
1386
|
+
#### Reasons for Change
|
|
1387
|
+
|
|
1388
|
+
Previously, Vue assigned component names based on the filename. This meant multiple pages like `pages/foo/index.vue` and `pages/bar/index.vue` would both have the component name `index`. This made `<KeepAlive>` with `include`/`exclude` filters unreliable and required manually adding `defineOptions({ name: '...' })` to each page.
|
|
1389
|
+
|
|
1390
|
+
#### Migration Steps
|
|
1391
|
+
|
|
1392
|
+
If you rely on the current component names (e.g. in `<KeepAlive>` `include`/`exclude` lists), update them to use route names instead of filenames.
|
|
1393
|
+
|
|
1394
|
+
```diff
|
|
1395
|
+
<template>
|
|
1396
|
+
<NuxtPage :keepalive="{
|
|
1397
|
+
- include: ['index']
|
|
1398
|
+
+ include: ['foo']
|
|
1399
|
+
}" />
|
|
1400
|
+
</template>
|
|
1401
|
+
```
|
|
1402
|
+
|
|
1403
|
+
To disable this behavior:
|
|
1404
|
+
|
|
1405
|
+
```ts twoslash [nuxt.config.ts]
|
|
1406
|
+
export default defineNuxtConfig({
|
|
1407
|
+
experimental: {
|
|
1408
|
+
normalizePageNames: false,
|
|
1409
|
+
},
|
|
1410
|
+
})
|
|
1411
|
+
```
|
|
1412
|
+
|
|
1377
1413
|
## Nuxt 2 vs. Nuxt 3+
|
|
1378
1414
|
|
|
1379
1415
|
In the table below, there is a quick comparison between 3 versions of Nuxt:
|
|
@@ -607,6 +607,30 @@ But in order to auto-import it, you would need to use `SomeFolderMyComponent`.
|
|
|
607
607
|
|
|
608
608
|
By setting `experimental.normalizeComponentNames`, these two values match, and Vue will generate a component name that matches the Nuxt pattern for component naming.
|
|
609
609
|
|
|
610
|
+
## normalizePageNames
|
|
611
|
+
|
|
612
|
+
Ensure that page component names match their route names. This sets the `__name` property on page components so that Vue's `<KeepAlive>` can correctly identify them by name.
|
|
613
|
+
|
|
614
|
+
By default, Vue assigns component names based on the filename. For example, `pages/foo/index.vue` and `pages/bar/index.vue` would both have the component name `index`. This makes name-based `<KeepAlive>` filtering unreliable because multiple pages share the same name.
|
|
615
|
+
|
|
616
|
+
With `normalizePageNames` enabled, page components are named after their route (e.g. `foo` and `bar`), so you can use `<KeepAlive>` with `include`/`exclude` without manually adding `defineOptions({ name: '...' })` to each page.
|
|
617
|
+
|
|
618
|
+
This flag is enabled when `future.compatibilityVersion` is set to `5` or higher, but you can disable this feature:
|
|
619
|
+
|
|
620
|
+
```ts twoslash [nuxt.config.ts]
|
|
621
|
+
export default defineNuxtConfig({
|
|
622
|
+
experimental: {
|
|
623
|
+
normalizePageNames: false,
|
|
624
|
+
},
|
|
625
|
+
})
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
```vue [app.vue]
|
|
629
|
+
<template>
|
|
630
|
+
<NuxtPage :keepalive="{ include: ['foo'] }" />
|
|
631
|
+
</template>
|
|
632
|
+
```
|
|
633
|
+
|
|
610
634
|
## spaLoadingTemplateLocation
|
|
611
635
|
|
|
612
636
|
When rendering a client-only page (with `ssr: false`), we optionally render a loading screen (from `~/spa-loading-template.html`).
|
|
@@ -36,6 +36,7 @@ export interface CookieOptions<T = any> extends Omit<CookieSerializeOptions & Co
|
|
|
36
36
|
default?: () => T | Ref<T>
|
|
37
37
|
watch?: boolean | 'shallow'
|
|
38
38
|
readonly?: boolean
|
|
39
|
+
refresh?: boolean
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
export interface CookieRef<T> extends Ref<T> {}
|
|
@@ -60,6 +61,7 @@ Most of the options will be directly passed to the [cookie](https://github.com/j
|
|
|
60
61
|
| `encode` | `(value: T) => string` | `JSON.stringify` + `encodeURIComponent` | Custom function to encode the cookie value. Since the value of a cookie has a limited character set (and must be a simple string), this function can be used to encode a value into a string suited for a cookie's value. |
|
|
61
62
|
| `default` | `() => T \| Ref<T>` | `undefined` | Function returning the default value if the cookie does not exist. The function can also return a `Ref`. |
|
|
62
63
|
| `watch` | `boolean \| 'shallow'` | `true` | Whether to watch for changes and update the cookie. `true` for deep watch, `'shallow'` for shallow watch, i.e. data changes for only top level properties, `false` to disable. <br/> **Note:** Refresh `useCookie` values manually when a cookie has changed with [`refreshCookie`](/docs/4.x/api/utils/refresh-cookie). |
|
|
64
|
+
| `refresh` | `boolean` | `false` | If `true`, the cookie expiration will be refreshed on every explicit write (e.g. `cookie.value = cookie.value`), even if the value itself hasn’t changed. Note: the expiration is not refreshed automatically — you must assign to `.value` to trigger it. |
|
|
63
65
|
| `readonly` | `boolean` | `false` | If `true`, disables writing to the cookie. |
|
|
64
66
|
| `maxAge` | `number` | `undefined` | Max age in seconds for the cookie, i.e. the value for the [`Max-Age` `Set-Cookie` attribute](https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.2). The given number will be converted to an integer by rounding down. By default, no maximum age is set. |
|
|
65
67
|
| `expires` | `Date` | `undefined` | Expiration date for the cookie. By default, no expiration is set. Most clients will consider this a "non-persistent cookie" and will delete it on a condition like exiting a web browser application. <br/> **Note:** The [cookie storage model specification](https://datatracker.ietf.org/doc/html/rfc6265#section-5.3) states that if both `expires` and `maxAge` is set, then `maxAge` takes precedence, but not all clients may obey this, so if both are set, they should point to the same date and time! <br/>If neither of `expires` and `maxAge` is set, the cookie will be session-only and removed when the user closes their browser. |
|
|
@@ -163,6 +165,28 @@ function save () {
|
|
|
163
165
|
</template>
|
|
164
166
|
```
|
|
165
167
|
|
|
168
|
+
### Refreshing Cookies
|
|
169
|
+
|
|
170
|
+
```vue
|
|
171
|
+
<script setup lang="ts">
|
|
172
|
+
const session = useCookie(
|
|
173
|
+
'session', {
|
|
174
|
+
maxAge: 60 * 60, // 1 hour
|
|
175
|
+
refresh: true,
|
|
176
|
+
default: () => 'active',
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
// Even if the value does not change,
|
|
180
|
+
// the cookie expiration will be refreshed
|
|
181
|
+
// every time the setter is called
|
|
182
|
+
session.value = 'active'
|
|
183
|
+
</script>
|
|
184
|
+
|
|
185
|
+
<template>
|
|
186
|
+
<div>Session: {{ session }}</div>
|
|
187
|
+
</template>
|
|
188
|
+
```
|
|
189
|
+
|
|
166
190
|
### Cookies in API Routes
|
|
167
191
|
|
|
168
192
|
You can use `getCookie` and `setCookie` from [`h3`](https://github.com/h3js/h3) package to set cookies in server API routes.
|