将url params传递给私有路由_反应路由器

问题描述 投票:0回答:1

在路由器中,我们可以使用{this.props.match.params.id}来匹配我们想要映射的某个对象的详细信息。

<Route path="/userDetail/:id" exact component={UserDetail} />

在该组件中,我们可以访问:id

但在自定义路线中我们如何达到这个目标?我在this.props.computedMatch.params.id中找到了:id

但我想把它传递给this.props.match

let PrivateRoute = ({ component: ChildComponent, isLogin, ...rest}) => {
      return <Route render={props => {
        if (!this.props.get.isLogin) {
            return <Redirect to="/login" />;
        } else {
          return <ChildComponent {...props} />
        }
      }} />

<Switch>
     <PrivateRoute path="/userDetail/:id"  exact component={UserDetail} />

</Switch>
reactjs react-router
1个回答
1
投票

您还需要包含传递到路线中的其他道具:

<ChildComponent {...props} {...rest} />
© www.soinside.com 2019 - 2024. All rights reserved.