2016-12-02 136 views

回答

0

由於RRv4是所有有關組件,該解決方案是在一個組件來處理這一點。基本上在示例中列出,其中重定向該<MatchWhenAuthorized>部件的相反,如果用戶已登錄。

const MatchWhenUnauthorized = ({ component: Component, ...rest }) => (
    <Match {...rest} render={props => (
    !fakeAuth.isAuthenticated ? (
     <Component {...props}/> 
    ) : (
     <Redirect to={{ pathname: '/' }}/> 
    ) 
)}/> 
) 

這類似於你會與正常的路由/視圖配置(匹配/login做什麼和在login如果用戶已經通過身份驗證,您將重定向)。