@nuxt/docs-nightly 5.0.0-29787185.8dc3f5fd → 5.0.0-29788347.3c4e1708
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.
|
@@ -616,6 +616,43 @@ export default defineNuxtConfig({
|
|
|
616
616
|
})
|
|
617
617
|
```
|
|
618
618
|
|
|
619
|
+
## navigateToEarlyReturn
|
|
620
|
+
|
|
621
|
+
Transform top-level `await navigateTo()` calls in `<script setup>` into an early return from the compiled `setup()` function when the navigation succeeds.
|
|
622
|
+
|
|
623
|
+
Without this flag, code after `await navigateTo()` continues to run, which can result in later code (including subsequent `navigateTo` calls) overriding the redirect or attempting to render a page with missing data. With this flag enabled, a successful navigation stops execution of the rest of your setup code and the component renders a placeholder comment while the navigation proceeds.
|
|
624
|
+
|
|
625
|
+
This flag is enabled by default with `compatibilityVersion: 5`, but you can disable it:
|
|
626
|
+
|
|
627
|
+
```ts twoslash [nuxt.config.ts]
|
|
628
|
+
export default defineNuxtConfig({
|
|
629
|
+
experimental: {
|
|
630
|
+
navigateToEarlyReturn: false,
|
|
631
|
+
},
|
|
632
|
+
})
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
```vue [pages/example.vue]
|
|
636
|
+
<script setup lang="ts">
|
|
637
|
+
const { data } = await useFetch('/api/data')
|
|
638
|
+
|
|
639
|
+
if (!data.value) {
|
|
640
|
+
await navigateTo('/fallback')
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// with the flag enabled, this only runs if the navigation did not happen
|
|
644
|
+
const processed = data.value!.map(item => item.name)
|
|
645
|
+
</script>
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
The transform only applies to top-level `await navigateTo()` statements in `<script setup>` whose result is not used. Calls with the `open` option (or options that cannot be statically analysed) are not transformed, as they should not stop the current page from rendering.
|
|
649
|
+
|
|
650
|
+
The early return only happens when the navigation succeeds (that is, when `navigateTo` resolves to `undefined`). If the navigation is aborted or fails (for example, blocked by a navigation guard, or navigating to the current route), the rest of your setup code continues to run. On a successful navigation, nothing after the `navigateTo` call runs: this includes `defineExpose` and any lifecycle hook registrations later in `<script setup>`.
|
|
651
|
+
|
|
652
|
+
::read-more{icon="i-simple-icons-github" to="https://github.com/nuxt/nuxt/issues/23698" target="_blank"}
|
|
653
|
+
See full explanation on the GitHub issue.
|
|
654
|
+
::
|
|
655
|
+
|
|
619
656
|
## normalizeComponentNames
|
|
620
657
|
|
|
621
658
|
Nuxt updates auto-generated Vue component names to match the full component name you would use to auto-import the component.
|
|
@@ -41,6 +41,10 @@ await navigateTo({
|
|
|
41
41
|
</script>
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
+
::note
|
|
45
|
+
Calling `navigateTo` does not stop execution of the rest of your `<script setup>` code. If you want a successful navigation to return early from `setup()`, enable [`experimental.navigateToEarlyReturn`](/docs/4.x/guide/going-further/experimental-features#navigatetoearlyreturn).
|
|
46
|
+
::
|
|
47
|
+
|
|
44
48
|
### Within Route Middleware
|
|
45
49
|
|
|
46
50
|
```ts
|