@nuxt/docs-nightly 5.0.0-29787188.1d507ee7 → 5.0.0-29788537.bc41aa9c

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.
@@ -253,6 +253,31 @@ export default defineNuxtConfig({
253
253
  })
254
254
  ```
255
255
 
256
+ ## early404
257
+
258
+ Responds with an early 404 error for requests whose path cannot match any page route, without loading the Vue app, its plugins or middleware on the server.
259
+
260
+ Page routes (including aliases) are compiled into a static route matcher at build time, and incoming requests are checked against it before server-side rendering begins. Requests that cannot match any page skip loading the app entirely and go straight to the error page.
261
+
262
+ Requests without an `Accept: text/html` header (API clients, most scanners) receive a JSON error without loading the app at all. HTML requests still server-render the error page. A [`cache` route rule](/docs/4.x/guide/concepts/rendering#hybrid-rendering) covering the path advertises its `maxAge` as `Cache-Control` on GET/HEAD misses too, letting a CDN absorb repeat requests for unknown paths.
263
+
264
+ ```ts twoslash [nuxt.config.ts]
265
+ export default defineNuxtConfig({
266
+ experimental: {
267
+ early404: true,
268
+ },
269
+ })
270
+ ```
271
+
272
+ ::warning
273
+ This is opt-in because it can break apps that rely on runtime routing:
274
+
275
+ - pages added dynamically with `router.addRoute()` in a plugin. To surface this early, `addRoute` is removed from the type of the router returned by [`useRouter`](/docs/4.x/api/composables/use-router) when the option is enabled.
276
+ - route middleware that redirects unknown paths to existing pages
277
+
278
+ The option is disabled automatically in development, when `hashMode` is enabled, when a root-level catch-all page (such as `pages/[...slug].vue`) matches every path, and when a custom `app/router.options` file may modify `routes` (a file whose default export is a plain object without a `routes` key remains compatible).
279
+ ::
280
+
256
281
  ## clientFallback
257
282
 
258
283
  Enables the experimental [`<NuxtClientFallback>`](/docs/4.x/api/components/nuxt-client-fallback) component for rendering content on the client if there's an error in SSR.
@@ -616,6 +641,43 @@ export default defineNuxtConfig({
616
641
  })
617
642
  ```
618
643
 
644
+ ## navigateToEarlyReturn
645
+
646
+ Transform top-level `await navigateTo()` calls in `<script setup>` into an early return from the compiled `setup()` function when the navigation succeeds.
647
+
648
+ 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.
649
+
650
+ This flag is enabled by default with `compatibilityVersion: 5`, but you can disable it:
651
+
652
+ ```ts twoslash [nuxt.config.ts]
653
+ export default defineNuxtConfig({
654
+ experimental: {
655
+ navigateToEarlyReturn: false,
656
+ },
657
+ })
658
+ ```
659
+
660
+ ```vue [pages/example.vue]
661
+ <script setup lang="ts">
662
+ const { data } = await useFetch('/api/data')
663
+
664
+ if (!data.value) {
665
+ await navigateTo('/fallback')
666
+ }
667
+
668
+ // with the flag enabled, this only runs if the navigation did not happen
669
+ const processed = data.value!.map(item => item.name)
670
+ </script>
671
+ ```
672
+
673
+ 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.
674
+
675
+ 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>`.
676
+
677
+ ::read-more{icon="i-simple-icons-github" to="https://github.com/nuxt/nuxt/issues/23698" target="_blank"}
678
+ See full explanation on the GitHub issue.
679
+ ::
680
+
619
681
  ## normalizeComponentNames
620
682
 
621
683
  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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/docs-nightly",
3
- "version": "5.0.0-29787188.1d507ee7",
3
+ "version": "5.0.0-29788537.bc41aa9c",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",