<Route exact path="inbox" component={Inbox}>
  </Route>
    <Route path="inbox/messages/:id" component={Message} >
    </Route>
  render() {
    // 来自于路径 `/inbox/messages/:id`
    const id = this.props.match.params.id;
    console.log(id,this)
    }

可先在这Message组件打印this出来,看this里哪个key的值为路由参数值

如果函数组件获取路由参数,请参考下面链接
https://reactrouter.com/web/example/url-params

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐