请问这种react组件写法换成class的写法应该怎么写?

const PrivateRoute = ({ component: Component, ...rest }) => (
  <Route
    {...rest}
    render={props =>
      fakeAuth.isAuthenticated ? (
        <Component {...props} />
      ) : (
        <Redirect
          to={{
            pathname: "/login",
            state: { from: props.location }
          }}
        />
      )
    }
  />
);

(在下看不懂上面这种的写法)
请问上面的写法如何翻译成 class App extends Component {...} 这种写法?
https://reacttraining.com/react-router/web/example/auth-workflow

阅读 2k
1 个回答
class PrivateRoute extends React.Component {

    render(){
        const { component: Component, ...rest } = this.props
        
        return (
            <Route
                {...rest}
                render={props =>
                  fakeAuth.isAuthenticated ? (
                    <Component {...props} />
                  ) : (
                    <Redirect
                      to={{
                        pathname: "/login",
                        state: { from: props.location }
                      }}
                    />
                  )
                }
              />)
    }
  
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题