1.vue中路由獨享守衛意思就是對這個路由有一個單獨的守衛,因為他的守衛方式於其他的凡是不太同
獨享守衛於前置守衛使用方法大致是一樣的
- 在路由配置的時候進行配置,
{ path:'/login', component:Login, beforeEnter(to,from,next){ to.query.returnURL = from.path; next(); } }
2.在登陸界面就是需要返回的頁面進行操作
login(){ axios.post('/user/login',this.user).then((res)=>{ localStorage.setItem('token',"Bearer "+res.data.res.token) const url = this.$route.query.returnURL // // console.log(this.$route) this.$router.replace(url) }) }
rangthis.$router.replace(url),返回到點擊進來 的頁面,這樣就可以實現返回的操作,當時returnURL不會在地址欄上進行顯示