1、安装
npm install vue-router --save
2、在main.js里引入
import router from ‘./router’
3、配置路由
①创建组建引入组建
import Center from ‘@/views/Center’
②定义路由
const routes = [{
path: ‘/center’,
component: Center
},
]
③实例化VueRouter
const router = new VueRouter({
routes
})
④挂载
new Vue({
router,
render: h => h(App)
}).$mount(’#app’)
⑤根组件的模板里放上
⑥根据按钮跳转时
首页
编程式导航路由跳转
this.$router.push({ path: ‘home’})