step1:下载安装
npm i vue-router -S
step2:main.js中引入
import VueRouter from 'vue-router'
step3:安装插件
Vue.use(VueRouter)
step4:创建路由对象并配置路由规则
let router = new VueRouter({
routes: [{
path: '/home', component: Home
},{
path: '/error', component: Error
},{
path: '/user', component: User
},,{
path: '*', redirect: '/home'
}]
})
step5:将路由对象传递给Vue实例
step6:在app.vue中预留路由位置
step7:封装编程式导航的插件并注册至Vue
https://blog.csdn.net/weixin_40825228/article/details/102490947
step8:使用
this.pop()
this.push(/home)
this.repalce(/error)
来源:https://blog.csdn.net/weixin_40825228/article/details/102748964