📜  react js中的私有路由 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:03:23.908000             🧑  作者: Mango

代码示例1
const PrivateRoute = ({component: Component, ...rest}) => {
  const {isAuthenticated} = rest;

  return (
     (
      isAuthenticated ? (
        
      ) : (
        
      )
    )}
    />
  );
};

PrivateRoute.propTypes = {
  isAuthenticated: PropTypes.bool.isRequired,
};

function mapStateToProps(state) {
  return {
    isAuthenticated: state.user.isAuthenticated,
  };
}

export default connect(mapStateToProps)(PrivateRoute);