Skip to content

Commit d68f47e

Browse files
committed
types(router): added router array type for Array RouteConfig
1 parent 1e663df commit d68f47e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

packages/@vue/cli-plugin-router/generator/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module.exports = (api, options = {}) => {
1010

1111
api.render('./template', {
1212
historyMode: options.historyMode,
13-
doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript')
13+
doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript'),
14+
hasTypeScript: api.hasPlugin('typescript')
1415
})
1516

1617
if (api.invoking) {

packages/@vue/cli-plugin-router/generator/template/src/router/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import Vue from 'vue'
2+
<%_ if (hasTypeScript) { _%>
3+
import VueRouter, { RouteConfig } from 'vue-router'
4+
<%_ } else { _%>
25
import VueRouter from 'vue-router'
6+
<%_ } _%>
37
import Home from '../views/Home.vue'
48

5-
Vue.use(VueRouter)
6-
7-
const routes = [
9+
<%_ if (hasTypeScript) { _%>
10+
const routes = <Array<RouteConfig>>[
11+
<%_ } else { _%>
12+
const routes = [
13+
<%_ } _%>
814
{
915
path: '/',
1016
name: 'home',
@@ -26,6 +32,8 @@ const routes = [
2632
}
2733
]
2834

35+
Vue.use(VueRouter)
36+
2937
const router = new VueRouter({
3038
<%_ if (historyMode) { _%>
3139
mode: 'history',

0 commit comments

Comments
 (0)