在Vue中除了router-link,使用a标签的形式来实现跳转,还有一种方式使用window.location.href的形式,叫作编程式导航,就是写js代码跳转。编程
一:router.push():this
这个方法,和点击<router-link :to="...">是同样的router
1.最简单的:this.$router.push( '/home/newsinfo'+id )------>字符串路径对象
2.传递对象的:this.$router.push( { path:'/home/newsinfo'+id } )路由
3.传递命名路由:this.$router.push( {name: 'NewsInfo' , params:{ id: id }})字符串
4.带查询参数,变成 /newsinfo ?plan=privateio
this.$router.push( { path: ' newsinfo ', query :{ plan: 'private'} })route
二:router.replace():方法
它和router.push很像,惟一的不一样就是,它不会向history添加新记录,而是跟它的方法名同样----替换掉当前的history记录。命名
这个方法和<router-link :to="..." replace>是同样的;