iT邦幫忙

0

React 身份驗證

想要實做出使用者登入後,
根據身份給予不同的頁面,

https://ithelp.ithome.com.tw/upload/images/20200508/20111873UAdE1J2rHm.png

但我要如何在使用者登入後根據他的身份給予它不同的component頁面,
因為這些頁面還是需要Route去控制path,如上圖所示

目前的Route規劃:

<AuthProvider>
    <Router>
        <Switch>
            <Route exact path="/" component={Login} />
        </Switch>
    </Router>
</AuthProvider>

目前已知紀錄使用者的登入狀態有三種方式(如有錯請各位大大糾正):

  1. 使用redux
  2. 使用react context
  3. react router的PrivateRoute

目前參考的code

感謝您的解答

這個用redux 會比較好管理,你應該先看這個
https://reacttraining.com/react-router/web/example/auth-workflow
,跟`Dan`的 redux 存local storage的教學
https://egghead.io/lessons/javascript-redux-persisting-the-state-to-the-local-storage
p39212053 iT邦新手 4 級 ‧ 2020-05-12 07:27:10 檢舉
謝謝,我再研究看看~
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答