Skip to content

Commit 74b155b

Browse files
committed
docs: improve readme
1 parent cde9030 commit 74b155b

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Check the [playground](https://github.com/vuejs/vue-router-next/tree/master/play
2626

2727
- `base` option is now passed as the first argument to `createWebHistory` (and other histories)
2828
- Catch all routes (`/*`) must now be defined using a parameter with a custom regex: `/:catchAll(.*)`
29-
- `router.match` and `router.resolve` are merged together into `router.resolve` with a slightly different signature
29+
- `router.match` and `router.resolve` are merged together into `router.resolve` with a slightly different signature. Check it's typing through autocomplete or [Router's `resolve` method](https://github.com/vuejs/vue-router-next/blob/master/src/router.ts)
3030
- `router.getMatchedComponents` is now removed as they can be retrieved from `router.currentRoute.value.matched`:
3131
```js
3232
router.currentRoute.value.matched
@@ -42,9 +42,10 @@ Check the [playground](https://github.com/vuejs/vue-router-next/tree/master/play
4242
Otherwise there will be an initial transition as if you provided the `appear` prop to `transition` because the router displays its initial ___location (nothing) and then displays the first ___location. This happens because navigations are all asynchronous now. **If you have navigation guards upon the initial navigation**, you might not want to block the app render until they are resolved.
4343
- On SSR, you need to manually pass the appropriate history by using a ternary:
4444
```js
45+
// router.js
4546
let history = isServer ? createMemoryHistory() : createWebHistory()
4647
let router = createRouter({ routes, history })
47-
// on server only
48+
// somewhere in your server-entry.js
4849
router.push(req.url) // request url
4950
router.isReady().then(() => {
5051
// resolve the request
@@ -54,7 +55,7 @@ Check the [playground](https://github.com/vuejs/vue-router-next/tree/master/play
5455

5556
### Typings
5657

57-
To make typings more consistent and expressive, some types have been renamed. Keep in mind these can change until stable release to ensure consistency. Some types might have changed as well.
58+
To make typings more consistent and expressive, some types have been renamed. Keep in mind these can change until stable release to ensure consistency. Some type properties might have changed as well.
5859

5960
| `vue-router@3` | `vue-router@4` |
6061
| -------------- | ----------------------- |
@@ -71,7 +72,7 @@ These are technically breaking changes but they fix an inconsistent behavior.
7172
- Empty children `path` does not append a trailing slash (`/`) anymore to make it consistent across all routes:
7273
- By default no route has a trailing slash but also works with a trailing slash
7374
- Adding `strict: true` to a route record or to the router options (alongside `routes`) will disallow an optional trailing slash
74-
- Combining the point above with a trailing slash in your routes allows you to enforce a trailing slash in your routes. In the case of nested routes, make sure to add the trailing slash to the parent:
75+
- Combining `strict: true` with a trailing slash in your routes allows you to enforce a trailing slash in your routes. In the case of nested routes, make sure to add the trailing slash to the parent **and not the empty child**:
7576
```js
7677
let routes = [
7778
{
@@ -80,14 +81,24 @@ These are technically breaking changes but they fix an inconsistent behavior.
8081
},
8182
]
8283
```
83-
- To redirect the user to trailing slash routes (or the opposite), you can setup a `beforeEach` navigation guard that ensures the presence of a trailing slash
84+
- To redirect the user to trailing slash routes (or the opposite), you can setup a `beforeEach` navigation guard that ensures the presence of a trailing slash:
85+
```js
86+
router.beforeEach((to, from, next) => {
87+
if (to.path.endsWith('/')) next()
88+
else next({ path: to.path + '/', query: to.query, hash: to.hash })
89+
})
90+
```
8491
- Because of the change above, relative children path `redirect` on an empty path are not supported anymore. Use named routes instead:
8592
```js
8693
// replace
8794
let routes = [
8895
{
8996
path: '/parent',
90-
children: [{ path: '', redirect: 'home' }, { path: 'home' }],
97+
children: [
98+
// this would now redirect to `/home` instead of `/parent/home`
99+
{ path: '', redirect: 'home' },
100+
{ path: 'home' },
101+
],
91102
},
92103
]
93104
// with

0 commit comments

Comments
 (0)