Skip to content

Commit ac97473

Browse files
committed
docs: migration guide wip
1 parent be813c5 commit ac97473

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

docs/.vitepress/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ const config = {
120120
},
121121
],
122122
},
123+
{
124+
text: 'Migrating from Vue 2',
125+
link: '/guide/migration/',
126+
},
123127
],
124128
},
125129
},

docs/guide/migration/index.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Migrating from Vue 2
2+
3+
Most of Vue Router API has remained unchanged during its rewrite from v3 (for Vue 2) to v4 (for Vue 3) but there are still a few breaking changes that you might encounter while migrating your application. This guide is here to help you understand why these changes happened and how to adapt your application to make it work with Vue Router 4.
4+
5+
## New Features
6+
7+
Some of new features to keep an eye on in Vue Router 4 include:
8+
9+
<!-- TODO: links -->
10+
11+
- Dynamic Routing
12+
- Composition API
13+
- Custom History implementation
14+
15+
## Breaking
16+
17+
### Improvements
18+
19+
The following changes should not be a problem for you but they are technically breaking changes that will show a different behavior and might break parts of your application.
20+
21+
### Non existent named routes
22+
23+
Pushing or resolving a non existent named route throws an error:
24+
25+
```js
26+
// Oops, we made a typo in name
27+
router.push({ name: 'homee' }) // throws
28+
router.resolve({ name: 'homee' }) // throws
29+
```
30+
31+
**Reason**: Previously, the router would navigate to `/` but display nothing (instead of the home page). Throwing an error makes more sense because we cannot produce a valid URL to navigate to.
32+
33+
### Missing required `params` on named routes
34+
35+
Pushing or resolving a named route without its required params will throw an error:
36+
37+
```js
38+
// given the following route:
39+
const routes = [{ path: '/users/:id', name: 'users' }]
40+
41+
// Missing the `id` param will fail
42+
router.push({ name: 'users' })
43+
router.resolve({ name: 'users' })
44+
```
45+
46+
**Reason**: Same as above.
47+
48+
### Empty `path` in children no longer produces a trailing slash
49+
50+
Given any nested routes with an empty `path`:
51+
52+
```js
53+
const routes = [
54+
{
55+
path: '/dashboard',
56+
name: 'dashboard-parent',
57+
children: [
58+
{ path: '', name: 'dashboard' },
59+
{ path: 'settings', name: 'dashboard-settings' },
60+
],
61+
},
62+
]
63+
```
64+
65+
Navigating to the named route `dashboard` will now produce a URL **without a trailing slash**.
66+
67+
Both `/dashboard` and `/dashboard/` will access the named route _dashboard_ and not _dashboard-parent_
68+
69+
**Reason**: This is to make things consistent

0 commit comments

Comments
 (0)