React router private routes / redirect not working

后端 未结 9 1241
轮回少年
轮回少年 2020-12-07 16:57

I have slightly adjusted the React Router example for the private routes to play nice with Redux, but no components are rendered when Linking or Redirecting to other \'pages

9条回答
  •  太阳男子
    2020-12-07 17:08

    Just had same problem, I solved it by making my App redux container and passing isAuthenticated as a prop to PrivateRoute

    Here it is, I hope it helps

    const App = (props) => {
    return (
      
        
          
    ); }; const mapStateToProps = state => ({ isAuthenticated: state.isAuthenticated }); export default connect(mapStateToProps)(App);

    Then in my PrivateRoute

    const PrivateRoute = ({ component: Component, isAuthenticated, ...rest}) => (
     (
        isAuthenticated
        ? (
           
        )
        : ()
      )}
    />
    );
    
    export default PrivateRoute;
    

提交回复
热议问题