Vue 编程式导航(通过js跳转页面)以及路由hash模式和history模式

第一种方法:
this.$router.push({path:'shopcontent?aid=3'}
 
第二种方法
 
this.$router.push({name:'news'}}
通过在main.js中配置路由时给router加上name 属性
const routes = [
 
{ path: '/Home', component: Home },
{ path: '/News', component: News,name:'news'},
{ path: '/Shopcontent', component:Shopcontent},
{ path: '/Content/:aid', component:Content},
]
 
路由的默认模式为hash模式要改为history模式
在实例化vuerouter的时候加上mode
const router = new VueRouter({
mode:'history',
routes // (缩写)相当于 routes: routes
})
 
原文地址:https://www.cnblogs.com/changedman/p/9222700.html