dva 路由权鉴

在路由文件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过期了无法判断

猜你喜欢

转载自www.cnblogs.com/unreal-feather/p/10332151.html
dva