Skip to content

Commit b9cd2f6

Browse files
committed
docs: add example of nested named routes
Closes #1921
1 parent c06e623 commit b9cd2f6

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Diff for: docs/en/essentials/named-views.md

+55
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,58 @@ const router = new VueRouter({
2727
```
2828

2929
A working demo of this example can be found [here](https://jsfiddle.net/posva/6du90epg/).
30+
31+
## Nested Named Views
32+
33+
While being quite complex, it is possible to combine named views with nested view. When doing so, you will also need to name nested `router-view` components used. Let's take a Settings panel example:
34+
35+
```
36+
/settings/emails /settings/profile
37+
+-----------------------------------+ +------------------------------+
38+
| UserSettings | | UserSettings |
39+
| +-----+-------------------------+ | | +-----+--------------------+ |
40+
| | Nav | UserEmailsSubscriptions | | +------------> | | Nav | UserProfile | |
41+
| | +-------------------------+ | | | +--------------------+ |
42+
| | | | | | | | UserProfilePreview | |
43+
| +-----+-------------------------+ | | +-----+--------------------+ |
44+
+-----------------------------------+ +------------------------------+
45+
```
46+
47+
- `Nav` is just a regular compnonent
48+
- `UserSettings` is the view comopnent
49+
- `UserEmailsSubscriptions`, `UserProfile`, `UserProfilePreview` are nested view components
50+
51+
**Note**: _Let's forget about how the HTML/CSS should look like to represent such layout and focus on the components used_
52+
53+
```html
54+
<!-- UserSettings.vue -->
55+
<div>
56+
<h1>User Settings</h1>
57+
<NavBar/>
58+
<router-view/>
59+
<router-view name="helper"/>
60+
</div>
61+
```
62+
63+
_The nested view components are omitted here but you can find the full example at the end in the jsfiddle_
64+
65+
Then you can achieve the layout above with this route configuration:
66+
67+
```js
68+
{ path: '/settings',
69+
// You could also have named views at the top
70+
component: UserSettings,
71+
children: [{
72+
path: 'emails',
73+
component: UserEmailsSubscriptions
74+
}, {
75+
path: 'profile',
76+
components: {
77+
default: UserProfile,
78+
helper: UserProfilePreview
79+
}
80+
}]
81+
}
82+
```
83+
84+
A working demo of this example can be found [here](https://jsfiddle.net/posva/22wgksa3/).

0 commit comments

Comments
 (0)