为渲染功能组件反应 ProtectedRoutes

时间:2021-05-28 00:14:17

标签: reactjs

所以通常我会这样设置我的路线:

<Route exact path="/x" Component={xComponent}/> And my protected routes would look like

<ProtectedRoute exact path="/x" prop={this.prop} Component={xComponent}/>

问题是现在我正在使用渲染组件,所以我的组件现在看起来像

<Route exact path ="/x" render={(routeProps) => <Component {...routeProps}/>}/>

<ProtectedRoute exact path="/x" prop={this.prop} render={(routeProps) => <Component {...routeProps}/>}/>

抛出错误:

元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义。

我的 ProtectedRoute 组件看起来像这样

const ProtectedRoute = ({ component: Component, account, ...rest }) => {

我必须向 ProtectedRoute 传递什么才能使用渲染组件?

0 个答案:

没有答案