You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// when route changes and this component is already rendered,
91
87
// the logic will be slightly different.
92
-
beforeRouteUpdate(to, from, next) {
88
+
asyncbeforeRouteUpdate(to, from) {
93
89
this.post=null
94
-
getPost(to.params.id, (err, post) => {
95
-
this.setData(err, post)
96
-
next()
97
-
})
98
-
},
99
-
methods: {
100
-
setData(err, post) {
101
-
if (err) {
102
-
this.error=err.toString()
103
-
} else {
104
-
this.post= post
105
-
}
90
+
try {
91
+
this.post=awaitgetPost(to.params.id)
92
+
} catch (error) {
93
+
this.error=error.toString()
106
94
}
107
-
}
95
+
},
108
96
}
109
97
```
110
98
111
99
The user will stay on the previous view while the resource is being fetched for the incoming view. It is therefore recommended to display a progress bar or some kind of indicator while the data is being fetched. If the data fetch fails, it's also necessary to display some kind of global warning message.
Copy file name to clipboardExpand all lines: docs/guide/advanced/meta.md
+24-13Lines changed: 24 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,30 +27,41 @@ const routes = [
27
27
28
28
So how do we access this `meta` field?
29
29
30
+
<!-- TODO: the explanation about route records should be explained before and things should be moved here -->
31
+
30
32
First, each route object in the `routes` configuration is called a **route record**. Route records may be nested. Therefore when a route is matched, it can potentially match more than one route record.
31
33
32
34
For example, with the above route config, the URL `/posts/new` will match both the parent route record (`path: '/posts'`) and the child route record (`path: 'new'`).
33
35
34
-
All route records matched by a route are exposed on the `$route` object (and also route objects in navigation guards) as the `$route.matched` Array. We could loop through that array to check all `meta` fields, but Vue Router also provides you a `$route.meta` that is first-level merge of **all `meta`** fields from parent to child. Meaning you can simply write
36
+
All route records matched by a route are exposed on the `$route` object (and also route objects in navigation guards) as the `$route.matched` Array. We could loop through that array to check all `meta` fields, but Vue Router also provides you a `$route.meta` that is a non-recursive merge of **all `meta`** fields from parent to child. Meaning you can simply write
35
37
36
38
```js
37
-
router.beforeEach((to, from, next) => {
39
+
router.beforeEach((to, from) => {
38
40
// instead of having to check every route record with
0 commit comments