ant design pro頁面重定向

場景1

項目中添加了license證書校驗,只有校驗通過纔可以訪問頁面,否則只要在地址欄輸入任一頁面路徑,都要重定向到license證書校驗頁面
實現代碼如下:

  • 引入

import Redirect from 'umi/redirect';
  • 渲染 \src\layouts\BasicLayout.js

<ContainerQuery query={query}>
  {params => (
    <Context.Provider value={this.getContext()}>
      <div className={classNames(params)}>
        {layout}
        {getLicenseStatus() === 'false' && pathname != '/license/byLogin' && (
          <Redirect to="/license/byLogin" />
        )}
      </div>
    </Context.Provider>
  )}
</ContainerQuery>

當獲取當前狀態爲false時,即license校驗失敗時,重定向到license校驗頁面

場景2

如果用戶尚未登錄,不能訪問其他登錄纔可以訪問的頁面
\src\pages\Authorized.js

 

return (
  <Authorized
    authority={getRouteAuthority(location.pathname, routerData)}
    noMatch={isLogin ? <Exception403 /> : <Redirect to="/user/login" />}
  >
    {children}
  </Authorized>
);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章