Skip to content

Commit 42896cb

Browse files
arggrandeAdam Grandeposva
authored
docs(migration): router.currentRoute (#1976)
Co-authored-by: Adam Grande <[email protected]> Co-authored-by: Eduardo San Martin Morote <[email protected]>
1 parent a3da735 commit 42896cb

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/docs/guide/migration/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ You don't need to add the `*` for repeated params if you don't plan to directly
113113

114114
**Reason**: Vue Router doesn't use `path-to-regexp` anymore, instead it implements its own parsing system that allows route ranking and enables dynamic routing. Since we usually add one single catch-all route per project, there is no big benefit in supporting a special syntax for `*`. The encoding of params is encoding across routes, without exception to make things easier to predict.
115115

116+
### The `currentRoute` property is now a `ref()`
117+
118+
Previously the properties of the [`currentRoute`](https://v3.router.vuejs.org/api/#router-currentroute) object on a router instance could be accessed directly.
119+
120+
With the introduction of vue-router v4, the underlying type of the `currentRoute` object on the router instance has changed to `Ref<RouteLocationNormalizedLoaded>`, which comes from the newer [reactivity fundamentals](https://vuejs.org/guide/essentials/reactivity-fundamentals.html) introduced in Vue 3.
121+
122+
While this doesn't change anything if you're reading the route with `useRoute()` or `this.$route`, if you're accessing it directly on the router instance, you will need to access the actual route object via `currentRoute.value`:
123+
124+
```ts
125+
const { page } = router.currentRoute.query // [!code --]
126+
const { page } = router.currentRoute.value.query // [!code ++]
127+
```
128+
116129
### Replaced `onReady` with `isReady`
117130

118131
The existing `router.onReady()` function has been replaced with `router.isReady()` which doesn't take any argument and returns a Promise:

0 commit comments

Comments
 (0)