Vue 路由的编程式导航与history模式

编程式导航

注意:官方文档写错了    通过javascript跳转


//第一种跳转方式

// this.$router.push({ path: 'news' })

// this.$router.push({ path: '/content/495' });

//另一种跳转方式

// { path: '/news', component: News,name:'news' },  //给路由起个名字

// router.push({ name: 'news', params: { userId: 123 }})  //  带参数跳转

this.$router.push({ name: 'news'})

}

history模式

在实例化vue-router(路由)时设置mode:'history',//默认是hash模式,界面效果地址栏没有#

注意:history模式下要结合后端服务器配置,官网有详细介绍。

注:路由可以嵌套,做类似与上下导航里带有左右导航

原文地址:https://www.cnblogs.com/1711643472qq/p/9155934.html