dva 路由權鑑

在路由文件router下session

  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('/'))
            }
        }

添加全局的路由監聽。而後判斷跳轉。app

這裏只能判斷本地的路由登陸狀況,若是token過時了沒法判斷ui

相關文章
相關標籤/搜索