脚手架项目在main.js中定义了路由,需要把main.js中的路由配置删除,然后把自己写的路由文件(我的是index.js)重新引用一下。
默认代码
1 // The Vue build version to load with the `import` command 2 // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 import Vue from ‘vue‘ 4 import FastClick from ‘fastclick‘ 5 import VueRouter from ‘vue-router‘ 6 import App from ‘./App‘ 7 import Home from ‘./pages/Home‘ 8 9 Vue.use(VueRouter) 10 11 const routes = [{ 12 path: ‘/‘, 13 component: Home 14 }] 15 16 const router = new VueRouter({ 17 routes 18 }) 19 20 FastClick.attach(document.body) 21 22 Vue.config.productionTip = false 23 24 /* eslint-disable no-new */ 25 new Vue({ 26 router, 27 render: h => h(App) 28 }).$mount(‘#app-box‘)
修改之后的代码
// The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from ‘vue‘ import FastClick from ‘fastclick‘ import VueRouter from ‘vue-router‘ import App from ‘./App‘ import router from ‘./router‘
Vue.use(VueRouter)
FastClick.attach(document.body)
Vue.config.productionTip = false
/* eslint-disable no-new */ new Vue({ router, render: h => h(App) }).$mount(‘#app-box‘)
原文:https://www.cnblogs.com/liu-xiaojian/p/10249140.html