一舆蝴、下載vue-router
npm install vue-router --save
二、編碼
1库车、在項(xiàng)目中新建文件夾 router/index.js
/*
* 路由對象模塊
* */
import Vue from 'vue'
import VueRouter from 'vue-router'
/*引入pages*/
const MSite = ()=>import('../pages/MSite/MSite');
const Profile = ()=>import('../pages/Profile/profile');
const Patient = ()=>import('../pages/Patient/Patient');
//申明使用插件
Vue.use(VueRouter)
export default new VueRouter({
routes:[
{
path:'/msite',
component: MSite,
meta: {
showFooter: true
}
},
{
path:'/profile',
component:Profile,
meta: {
showFooter: true
}
},
{
path:'/patient',
component:Patient,
meta: {
showFooter: false
}
},
{
path: '/',
redirect: '/msite' //系統(tǒng)默認(rèn)頁
}
]
})
2睁宰、在main.js中全局使用router
// 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 App from './App'
import router from './router' //引入路由
/* eslint-disable no-new */
new Vue({
el: '#app',
components: { App },
template: '<App/>',
router //引入路由
})