Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: omitting parent components for nested routes #2127

Merged
merged 2 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const i18nLabels = {
}

const theme: Theme = {
...DefaultTheme,
extends: DefaultTheme,
Layout() {
return h(DefaultTheme.Layout, null, {
// 'home-features-after': () => h(HomeSponsors),
Expand Down
21 changes: 21 additions & 0 deletions packages/docs/guide/essentials/nested-routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
posva marked this conversation as resolved.
Show resolved Hide resolved