React router private routes / redirect not working

后端 未结 9 1253
轮回少年
轮回少年 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:18

    I have the similar issue like @Rein. In my case, PrivateRoute looks almost same to the original version but only connected to Redux and used it instead of fakeAuth in the original example.

    const PrivateRoute = ({ component: Component, auth, ...rest }) => (
      
       auth.isAuthenticated
        ? 
        : }
      />
    );
    
     PrivateRoute.propTypes = {
      auth: PropTypes.object.isRequired,
      component: PropTypes.func.isRequired
     }
    
     const mapStateToProps = (state, ownProps) => {
      return {
         auth: state.auth
      }
    };
    
    export default connect(mapStateToProps)(PrivateRoute);
    

    Usage and result:-

    1. NOT working but expecting to work
    2. working but NOT desired to used like this
    3. working. JUST to work but NOT desired to used at all. An understanding from this point is that, if you connect original PrivateRoute to Redux, you need to pass some additional props (any prop)to make PrivateRoute working otherwise it does not work. Anyone, please give some hint on this behavior. This is my main concern. As a New Question at

提交回复
热议问题