diff --git a/packages/@vue/cli-plugin-router/generator/index.js b/packages/@vue/cli-plugin-router/generator/index.js index 94ee66c0cb..4789d45c4d 100644 --- a/packages/@vue/cli-plugin-router/generator/index.js +++ b/packages/@vue/cli-plugin-router/generator/index.js @@ -10,7 +10,8 @@ module.exports = (api, options = {}) => { api.render('./template', { historyMode: options.historyMode, - doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript') + doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript'), + hasTypeScript: api.hasPlugin('typescript') }) if (api.invoking) { diff --git a/packages/@vue/cli-plugin-router/generator/template/src/router/index.js b/packages/@vue/cli-plugin-router/generator/template/src/router/index.js index 60e7196c75..3f1acf1fd9 100644 --- a/packages/@vue/cli-plugin-router/generator/template/src/router/index.js +++ b/packages/@vue/cli-plugin-router/generator/template/src/router/index.js @@ -1,10 +1,18 @@ import Vue from 'vue' +<%_ if (hasTypeScript) { _%> +import VueRouter, { RouteConfig } from 'vue-router' +<%_ } else { _%> import VueRouter from 'vue-router' +<%_ } _%> import Home from '../views/Home.vue' Vue.use(VueRouter) -const routes = [ +<%_ if (hasTypeScript) { _%> + const routes: Array = [ +<%_ } else { _%> + const routes = [ +<%_ } _%> { path: '/', name: 'Home',