Vue 路由跳转总结
程序员文章站
2022-05-18 17:19:46
...
<div class = 'app'>
<router-view />
</div>
1: <route-link to="/login">
<div></div>
</route-link>
2:
this.$router.push('/')
router.push({
path:"/login",
query:{ }
})
3:
字符串: router.push('login')
对象: router.push( { path:' /login?url= ' + this.$route.path } )
命名的路由: this.$router.push( name:'user' ,params: {userID:123} )
带查询参数, (变成 /backend/order?selected=2): this.$router.push( { path:'/backend/order' , query:{ selected : " 2" } } )
设置查询参数 : this.$http.post( "vl/user/select-stage" , { state: state } )
.then( ( {data:{code , content } } ) =>{
if( code == 0 ){
//对象
this.$router.push( { path: ' /home' })
}else if(code == 10){
this.$router.push( { path:'/login' , query:{ stage: stage } } )
}
})
设计 查询参数对象 :
let queryData = {}
if( this.$route.query.stage ){
queryData.stage = this.$router.query.stage
}
if( this.$route.query.url ){
queryData.url = this.$route.query.url
}
this.$router.push( { path:'/my/profile ' , query:queryData } )
this.$router.push( { path:" .home" , replace:true} )
this.$router.push( { path:'/coach ' + this.$route.params.id , query:queryData } )
this.$router.replace()
描述:同样是跳转到指定的url,但是这个方法不会向history里面添加新的记录,点击返回,会跳转到上上一个页面。上一个记录是不存在的。