]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
docs: omitting parent components for nested routes (#2127)
authorskirtle <65301168+skirtles-code@users.noreply.github.com>
Sun, 4 Feb 2024 09:58:08 +0000 (09:58 +0000)
committerGitHub <noreply@github.com>
Sun, 4 Feb 2024 09:58:08 +0000 (10:58 +0100)
* docs: omitting parent components for nested routes

* Update packages/docs/guide/essentials/nested-routes.md

---------

Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
packages/docs/.vitepress/theme/index.ts
packages/docs/guide/essentials/nested-routes.md

index a024db948326d2f9f95b8d6c1d196b8db683a57d..4fd5c4eb090cb9f857146f70e3462e2c5df9aa5b 100644 (file)
@@ -15,7 +15,7 @@ const i18nLabels = {
 }
 
 const theme: Theme = {
-  ...DefaultTheme,
+  extends: DefaultTheme,
   Layout() {
     return h(DefaultTheme.Layout, null, {
       // 'home-features-after': () => h(HomeSponsors),
index 6a8ec20f46ae66194fe642853d905e04a0a3c883..c48241332ddf71d1d3835dc2d4bd8420093833b0 100644 (file)
@@ -128,3 +128,24 @@ const routes = [
   },
 ]
 ```
+
+## Omitting parent components <Badge text="4.1+" />
+
+We can also take advantage of the parent-child relationship between routes without needing to nest route components. This can be useful for grouping together routes with a common path prefix, or when working with [route meta fields](../advanced/meta).
+
+To achieve this, we omit the `component` and `components` options from the parent route:
+
+```js
+const routes = [
+  {
+    path: '/admin',
+    children: [
+      { path: '', component: AdminOverview },
+      { path: 'users', component: AdminUserList },
+      { path: 'users/:id', component: AdminUserDetails },
+    ], 
+  },
+]
+```
+
+As the parent doesn't specify a route component, the top-level `<router-view>` will skip over the parent and just use the component from the relevant child instead.