Skip to content

Commit bbed9a0

Browse files
Jinjiangposva
authored andcommitted
[docs][zh-cn] sync recent udpates to #9e78ca2 (#1984)
* [docs][zh-cn] sync recent udpates to #9e78ca2 * Update named-views.md
1 parent 6480339 commit bbed9a0

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

Diff for: docs/zh-cn/advanced/navigation-guards.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ router.beforeEach((to, from, next) => {
3434

3535
- **`next('/')` 或者 `next({ path: '/' })`**: 跳转到一个不同的地址。当前的导航被中断,然后进行一个新的导航。你可以向 `next` 传递任意位置对象,且允许设置诸如 `replace: true``name: 'home'` 之类的选项以及任何用在 [`router-link``to` prop](../api/router-link.md)[`router.push`](../api/router-instance.md#方法) 中的选项。
3636

37-
- **`next(error)`**: (2.4.0+) 如果传入 `next` 的参数是一个 `Error` 实例,则导航会被终止且该错误会被传递给 `router.onError()` 注册过的回调。
37+
- **`next(error)`**: (2.4.0+) 如果传入 `next` 的参数是一个 `Error` 实例,则导航会被终止且该错误会被传递给 [`router.onError()`](../api/router-instance.html#方法) 注册过的回调。
3838

3939
**确保要调用 `next` 方法,否则钩子就不会被 resolved。**
4040

Diff for: docs/zh-cn/essentials/named-views.md

+58
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,61 @@ const router = new VueRouter({
2626
```
2727

2828
以上案例相关的可运行代码请[移步这里](https://jsfiddle.net/posva/6du90epg/)
29+
30+
## 嵌套命名视图
31+
32+
我们也有可能使用命名视图创建嵌套视图的复杂布局。这时你也需要命名用到的嵌套 `router-view` 组件。我们以一个设置面板为例:
33+
34+
```
35+
/settings/emails /settings/profile
36+
+-----------------------------------+ +------------------------------+
37+
| UserSettings | | UserSettings |
38+
| +-----+-------------------------+ | | +-----+--------------------+ |
39+
| | Nav | UserEmailsSubscriptions | | +------------> | | Nav | UserProfile | |
40+
| | +-------------------------+ | | | +--------------------+ |
41+
| | | | | | | | UserProfilePreview | |
42+
| +-----+-------------------------+ | | +-----+--------------------+ |
43+
+-----------------------------------+ +------------------------------+
44+
```
45+
46+
- `Nav` 只是一个常规组件。
47+
- `UserSettings` 是一个视图组件。
48+
- `UserEmailsSubscriptions``UserProfile``UserProfilePreview` 是嵌套的视图组件。
49+
50+
**注意**_我们先忘记 HTML/CSS 具体的布局的样子,只专注在用到的组件上_
51+
52+
`UserSettings` 组件的 `<template>` 部分应该是类似下面的这段代码:
53+
54+
```html
55+
<!-- UserSettings.vue -->
56+
<div>
57+
<h1>User Settings</h1>
58+
<NavBar/>
59+
<router-view/>
60+
<router-view name="helper"/>
61+
</div>
62+
```
63+
64+
_嵌套的视图组件在此已经被忽略了,但是你可以在[这里](https://jsfiddle.net/posva/22wgksa3/)找到完整的源代码_
65+
66+
然后你可以用这个路由配置完成该布局:
67+
68+
```js
69+
{
70+
path: '/settings',
71+
// 你也可以在顶级路由就配置命名视图
72+
component: UserSettings,
73+
children: [{
74+
path: 'emails',
75+
component: UserEmailsSubscriptions
76+
}, {
77+
path: 'profile',
78+
components: {
79+
default: UserProfile,
80+
helper: UserProfilePreview
81+
}
82+
}]
83+
}
84+
```
85+
86+
一个可以工作的示例的 demo 在[这里](https://jsfiddle.net/posva/22wgksa3/)

0 commit comments

Comments
 (0)