feat!: make router a separate plugin (#4196)

* refactor: move router to its own plugin

* refactor: rename routerHistoryMode option to historyMode

* test: add @vue/cli-plugin-router tests

* feat: change src/router.js for most common use cases

* fix: fix cli-ui tests

* docs: Remove router root option from docs

* fix: add support for legacy router option
This commit is contained in:
Pavan Kumar Sunkara
2019-07-05 17:21:29 +02:00
committed by Haoqun Jiang
parent 9eadfe1eba
commit 246ae678cb
33 changed files with 305 additions and 187 deletions

View File

@@ -1274,7 +1274,7 @@ const ROUTER = 'vue-router-add'
api.onViewOpen(({ view }) => {
if (view.id === 'vue-project-plugins') {
if (!api.hasPlugin('vue-router')) {
if (!api.hasPlugin('router')) {
api.addSuggestion({
id: ROUTER,
type: 'action',
@@ -1282,7 +1282,7 @@ api.onViewOpen(({ view }) => {
message: 'org.vue.cli-service.suggestions.vue-router-add.message',
link: 'https://router.vuejs.org/',
async handler () {
await install(api, 'vue-router')
await install(api, 'router')
}
})
}

View File

@@ -52,13 +52,6 @@ You can pass generator options to the installed plugin (this will skip the promp
vue add @vue/eslint --config airbnb --lintOn save
```
`vue-router` and `vuex` are special cases - they do not have their own plugins, but you can add them nonetheless:
``` bash
vue add router
vue add vuex
```
If a plugin is already installed, you can skip the installation and only invoke its generator with the `vue invoke` command. The command takes the same arguments as `vue add`.
::: tip
@@ -112,7 +105,6 @@ Here's an example preset:
``` json
{
"useConfigFiles": true,
"router": true,
"vuex": true,
"cssPreprocessor": "sass",
"plugins": {
@@ -120,7 +112,8 @@ Here's an example preset:
"@vue/cli-plugin-eslint": {
"config": "airbnb",
"lintOn": ["save", "commit"]
}
},
"@vue/cli-plugin-router": {}
}
}
```

View File

@@ -1274,7 +1274,7 @@ const ROUTER = 'vue-router-add'
api.onViewOpen(({ view }) => {
if (view.id === 'vue-project-plugins') {
if (!api.hasPlugin('vue-router')) {
if (!api.hasPlugin('router')) {
api.addSuggestion({
id: ROUTER,
type: 'action',
@@ -1282,7 +1282,7 @@ api.onViewOpen(({ view }) => {
message: 'org.vue.cli-service.suggestions.vue-router-add.message',
link: 'https://router.vuejs.org/',
async handler () {
await install(api, 'vue-router')
await install(api, 'router')
}
})
}

View File

@@ -52,13 +52,6 @@ vue add @foo/bar
vue add @vue/eslint --config airbnb --lintOn save
```
Добавление `vue-router` и `vuex` — особый случай, у них нет собственных плагинов, но вы тем не менее можете их добавить:
``` bash
vue add router
vue add vuex
```
Если плагин уже установлен, вы можете пропустить установку и только вызвать его генератор с помощью команды `vue invoke`. Команда принимает такие же аргументы, как и `vue add`.
::: tip Совет
@@ -112,7 +105,6 @@ vue add vuex
``` json
{
"useConfigFiles": true,
"router": true,
"vuex": true,
"cssPreprocessor": "sass",
"plugins": {
@@ -120,7 +112,8 @@ vue add vuex
"@vue/cli-plugin-eslint": {
"config": "airbnb",
"lintOn": ["save", "commit"]
}
},
"@vue/cli-plugin-router": {}
}
}
```

View File

@@ -52,13 +52,6 @@ vue add @foo/bar
vue add @vue/eslint --config airbnb --lintOn save
```
`vue-router` 和 `vuex` 的情况比较特殊——它们并没有自己的插件,但是你仍然可以这样添加它们:
``` bash
vue add router
vue add vuex
```
如果一个插件已经被安装,你可以使用 `vue invoke` 命令跳过安装过程,只调用它的生成器。这个命令会接受和 `vue add` 相同的参数。
::: tip 提示
@@ -112,7 +105,6 @@ vue add vuex
``` json
{
"useConfigFiles": true,
"router": true,
"vuex": true,
"cssPreprocessor": "sass",
"plugins": {
@@ -120,7 +112,8 @@ vue add vuex
"@vue/cli-plugin-eslint": {
"config": "airbnb",
"lintOn": ["save", "commit"]
}
},
"@vue/cli-plugin-router": {}
}
}
```