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
@@ -41,16 +41,19 @@ In addition to `$route.params`, the `$route` object also exposes other useful in
41
41
42
42
One thing to note when using routes with params is that when the user navigates from `/user/johnny` to `/user/jolyne`, **the same component instance will be reused**. Since both routes render the same component, this is more efficient than destroying the old instance and then creating a new one. **However, this also means that the lifecycle hooks of the component will not be called**.
43
43
44
-
To react to params changes in the same component, you can simply watch the `$route` object:
44
+
To react to params changes in the same component, you can simply watch anything on the `$route` object, in this scenario, the `$route.params`:
45
45
46
46
```js
47
47
constUser= {
48
48
template:'...',
49
-
watch: {
50
-
$route(to, from) {
51
-
// react to route changes...
52
-
}
53
-
}
49
+
created() {
50
+
this.$watch(
51
+
() =>this.$route.params,
52
+
(toParams, previousParams) => {
53
+
// react to route changes...
54
+
}
55
+
)
56
+
},
54
57
}
55
58
```
56
59
@@ -59,10 +62,10 @@ Or, use the `beforeRouteUpdate` [navigation guard](../advanced/navigation-guards
0 commit comments