Skip to content

Commit 83488a5

Browse files
committed
chore: update readme [skip ci]
1 parent d9843fe commit 83488a5

File tree

1 file changed

+17
-152
lines changed

1 file changed

+17
-152
lines changed

README.md

Lines changed: 17 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,32 @@
1-
# vue-router-next [![CircleCI](https://circleci.com/gh/vuejs/vue-router-next.svg?style=svg)](https://circleci.com/gh/vuejs/vue-router-next)
1+
# vue-router-next [![beta](https://img.shields.io/npm/v/vue-router/next.svg)](https://www.npmjs.com/package/vue-router/v/next) [![CircleCI](https://circleci.com/gh/vuejs/vue-router-next.svg?style=svg)](https://circleci.com/gh/vuejs/vue-router-next)
22

33
## Status: Beta
44

55
- Most RFCs have been merged.
66
- All [merged RFCs](https://github.com/vuejs/rfcs/pulls?q=is%3Apr+is%3Amerged+label%3A3.x+label%3Arouter) have been implemented.
7-
- Vue CLI now has experimental support via [vue-cli-plugin-vue-next](https://github.com/vuejs/vue-cli-plugin-vue-next).
8-
- Check the [playground](https://github.com/vuejs/vue-router-next/tree/master/playground) or [e2e tests](https://github.com/vuejs/vue-router-next/tree/master/e2e/modal) for a usage example.
7+
- [Documentation](https://next.router.vuejs.org).
98

10-
## Know issues
9+
## Quickstart
1110

12-
<!-- TODO: put a link to the documentation instead -->
13-
14-
### Breaking changes compared to [email protected]
15-
16-
- The `mode: 'history'` option has been replaced with a more flexible one named `history`:
17-
18-
```js
19-
import { createRouter, createWebHistory } from 'vue-router'
20-
// there is also createWebHashHistory and createMemoryHistory
21-
22-
createRouter({
23-
history: createWebHistory(),
24-
routes: [],
25-
})
26-
```
27-
28-
- `base` option is now passed as the first argument to `createWebHistory` (and other histories)
29-
- Catch all routes (`/*`) must now be defined using a parameter with a custom regex: `/:catchAll(.*)`
30-
- `router.match` and `router.resolve` are merged together into `router.resolve` with a slightly different signature. Check its typing through autocomplete or [Router's `resolve` method](https://github.com/vuejs/vue-router-next/blob/master/src/router.ts)
31-
- `router.getMatchedComponents` is now removed as they can be retrieved from `router.currentRoute.value.matched`:
32-
33-
```js
34-
router.currentRoute.value.matched.flatMap(record =>
35-
Object.values(record.components)
36-
)
11+
- Vie CDN: `<script src="https://unpkg.com/vue-router@next"></script>`
12+
- In-browser playground on [CodeSandbox](https://codesandbox.io/s/vue-router-4-reproduction-hb9lh)
13+
- Add it to an existing Vue Project:
14+
```bash
15+
npm install vue-router@next
3716
```
3817

39-
- The `append` argument has been removed. You can manually concatenate the value to an existing `path` instead.
40-
41-
- `RouterLink`
42-
- `append` prop has been removed as well. Use the same workaround as above.
43-
- `event` prop has been removed. Use the `v-slot` API instead. See [RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0021-router-link-scoped-slot.md).
44-
- `tag` prop has been removed. Use the `v-slot` API instead. See [RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0021-router-link-scoped-slot.md).
45-
- `exact` prop has been removed. The caveat it was fixing is no longer present. See [RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0028-router-active-link.md).
46-
- If you use a `transition`, you may need to wait for the router to be _ready_ before mounting the app:
47-
48-
```js
49-
app.use(router)
50-
// Note: on Server Side, you need to manually push the initial ___location
51-
router.isReady().then(() => app.mount('#app'))
52-
```
18+
## Changes from Vue Router 3
5319

54-
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.
20+
Please consult the [Migration Guide](https://next.router.vuejs.org/guide/migration/).
5521

56-
- On SSR, you need to manually pass the appropriate history:
57-
58-
```js
59-
// router.js
60-
let history = isServer ? createMemoryHistory() : createWebHistory()
61-
let router = createRouter({ routes, history })
62-
// somewhere in your server-entry.js
63-
router.push(req.url) // request url
64-
router.isReady().then(() => {
65-
// resolve the request
66-
})
67-
```
68-
69-
- The object returned in `scrollBehavior` is now similar to [`ScrollToOptions`](https://developer.mozilla.org/en-US/docs/Web/API/ScrollToOptions): `x` is renamed to `left` and `y` is renamed to `top`. See [RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0035-router-scroll-position.md).
70-
- `transition` and `keep-alive` must now be used **inside** of `RouterView` via the `v-slot` API:
71-
72-
```vue
73-
<router-view v-slot="{ Component }">
74-
<transition>
75-
<keep-alive>
76-
<component :is="Component" />
77-
</keep-alive>
78-
</transition>
79-
</router-view>
80-
```
81-
82-
See more on the [KeepAlive](https://github.com/vuejs/vue-router-next/blob/master/e2e/keep-alive/index.ts) and the [Transition](https://github.com/vuejs/vue-router-next/blob/master/e2e/transitions/index.ts) examples. See [RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0034-router-view-keep-alive-transitions.md).
83-
84-
- `parent` is removed from Route locations (`this.$route` and object returned by `router.resolve`). You can still access it via the `matched` array:
85-
86-
```js
87-
const parent = this.$route.matched[this.$route.matched.length - 2]
88-
```
89-
90-
- `pathToRegexpOptions` and `caseSensitive` have been replaced with `sensitive` and `strict` options. They can also be directly passed when creating the router with `createRouter()`. Any other option has been removed as `path-to-regexp` is no longer used to parse paths.
91-
92-
### Typings
93-
94-
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.
95-
96-
| `vue-router@3` | `vue-router@4` |
97-
| -------------- | ----------------------- |
98-
| RouteConfig | RouteRecordRaw |
99-
| Location | RouteLocation |
100-
| Route | RouteLocationNormalized |
101-
102-
#### Improvements
103-
104-
These are technically breaking changes but they fix an inconsistent behavior.
105-
106-
- Pushing or resolving a non existent named route throws an error instead of navigating to `/` and displaying nothing.
107-
- _resolving_(`router.resolve`) or _pushing_ (`router.push`) a ___location with missing params no longer warns and produces an invalid URL (`/`), but explicitly throws an Error instead.
108-
- Empty children `path` does not append a trailing slash (`/`) anymore to make it consistent across all routes:
109-
110-
- By default no route has a trailing slash but also works with a trailing slash
111-
- Adding `strict: true` to a route record or to the router options (alongside `routes`) will disallow an optional trailing slash
112-
- 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**:
113-
114-
```js
115-
let routes = [
116-
{
117-
path: '/parent/',
118-
children: [{ path: '' }, { path: 'child1/' }, { path: 'child2/' }],
119-
},
120-
]
121-
```
122-
123-
- 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:
124-
125-
```js
126-
router.beforeEach((to, from, next) => {
127-
if (to.path.endsWith('/')) next()
128-
else next({ path: to.path + '/', query: to.query, hash: to.hash })
129-
})
130-
```
131-
132-
- Because of the change above, relative children path `redirect` on an empty path are not supported anymore. Use named routes instead:
133-
134-
```js
135-
// replace
136-
let routes = [
137-
{
138-
path: '/parent',
139-
children: [
140-
// this would now redirect to `/home` instead of `/parent/home`
141-
{ path: '', redirect: 'home' },
142-
{ path: 'home' },
143-
],
144-
},
145-
]
146-
// with
147-
let routes = [
148-
{
149-
path: '/parent',
150-
children: [
151-
{ path: '', redirect: { name: 'home' } },
152-
{ path: 'home', name: 'home' },
153-
],
154-
},
155-
]
156-
```
22+
## Contributing
15723

158-
Note this will work if `path` was `/parent/` as the relative ___location `home` to `/parent/` is indeed `/parent/home` but the relative ___location of `home` to `/parent` is `/home`
24+
See [Contributing Guide](https://github.com/vuejs/vue-router-next/blob/master/.github/contributing.md).
15925

160-
- Encoding is now more consistent. The initial navigation should yield the same results are in-app navigations.
161-
- Values in `path`, `fullPath` are not decoded anymore. They will appear as provided by the browser (most browsers provide them encoded).
162-
- `params`, `query` and `hash` are now all decoded
163-
- When using `push`, `resolve` and `replace` and providing a `string` ___location or a `path` property in an object, **it must be encoded**. `params`, `query` and `hash` must be provided in its decoded version.
26+
## Special Thanks
16427

165-
## Contributing
28+
<a href="https://www.browserstack.com">
29+
<img src="/assets/browserstack-logo-600x315.png" height="80" title="BrowserStack Logo" alt="BrowserStack Logo" />
30+
</a>
16631

167-
See [Contributing Guide](https://github.com/vuejs/vue-router-next/blob/master/.github/contributing.md).
32+
Special thanks to [BrowserStack](https://www.browserstack.com) for letting the maintainers use their service to debug browser specific issues.

0 commit comments

Comments
 (0)