import Vue from 'vue' import Router from 'vue-router' import Home from '@/pages/home/Home' import City from '@/pages/city/City' import Detail from '@/pages/detail/Detail' //这里的@类似一个别名,在build/webpack.base.conf.js的resolve.alias配置 Vue.use(Router)export default new Router({routes: [{path: '/',name: 'Home',component: Home}, {path: '/city',name: 'City',component: City}, {path: '/detail/:id',name: 'Detail',component: Detail}], })
src/main.js
import Vue from 'vue' import App from './App' import router from './router' //引入router/* eslint-disable no-new */ new Vue({el: '#app',router, //创建与挂载components: { App },template: '' })