码迷,mamicode.com
首页 > 其他好文 > 详细

dva 路由权鉴

时间:2019-01-28 23:48:12      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:===   outer   session   col   patch   login   登录   ati   else   

在路由文件router下

  history.listen(location => {
        const uid = sessionStorage.getItem(‘uid‘) || localStorage.getItem("uid")
        console.log(location.pathname)
        if (location.pathname === ‘/‘ || location.pathname === ‘/login‘) {
            if (uid) {
                app._store.dispatch(routerRedux.replace(‘/backstage‘))
              }
        }else{
            if(!uid){
                app._store.dispatch(routerRedux.push(‘/‘))
            }
        }

添加全局的路由监听。然后判断跳转。

这里只能判断本地的路由登录情况,如果token过期了无法判断

dva 路由权鉴

标签:===   outer   session   col   patch   login   登录   ati   else   

原文地址:https://www.cnblogs.com/unreal-feather/p/10332151.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!