【发布时间】:2019-09-20 07:11:45
【问题描述】:
我正在尝试在 react-router-dom (5.0.1) 中实现这个逻辑。这是我的路线:
<Route
path="/available-days"
render={props => isAdmin ? Auth(UserProfileView) : <Redirect to='/dashboard'/>}
/>
当idAdmin是true时,会导致错误:Objects are not valid as a React child。
我也试过这个:
<Route
path="/available-days"
render={props => isAdmin ? Auth(UserProfileView)({ ...props }) : <Redirect to='/dashboard'/>}
/>
然后我看到TypeError: Object(...)(...) is not a function。为什么我不能在渲染方法中使用 HOC,我怎样才能让它工作?顺便说一句,Auth(UserProfileView) 在组件方法中工作正常。
【问题讨论】:
-
你为什么不只使用
<UserProfileView {...props} />,然后只在那个组件中用Auth包装UserProfileView?
标签: reactjs react-router react-router-dom