vue中的路由独享守卫的理解

1.vue中路由独享守卫意思就是对这个路由有一个单独的守卫,因为他的守卫方式于其他的凡是不太同

独享守卫于前置守卫使用方法大致是一样的

  1. 在路由配置的时候进行配置,
{
        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不会在地址栏上进行显示

posted @ 2018-12-28 15:21  努力的小高  阅读(4545)  评论(0编辑  收藏  举报