search

Home  >  Q&A  >  body text

javascript - How to pass parameters in react-router-dom v4, and how to get parameters for the next component to jump to

Current parameter passing method:

<Link to={`/topics/${topic.id}`}>{topic.title}</Link>

1. Is the method of passing parameters correct?

Then jump to the next page, the address bar is:

http://localhost:8080/topics/33119

I thought this.props.params.id could get the parameters this way, but it doesn’t seem to work.
2. How to obtain the address bar parameters?

怪我咯怪我咯2757 days ago1104

reply all(2)I'll reply

  • 代言

    代言2017-06-12 09:34:47

    It has been solved. It is still somewhat different from react-router. Question and answer:

    1. Routing configuration

    <Route path="/topics/:id" component={Topics} />

    2. Page before jumping

    <Link to={`/topics/${topic.id}`} >点击跳转</Link>

    3. Get parameters from page topics after jumping

    this.props.match.params.id

    reply
    0
  • 女神的闺蜜爱上我

    女神的闺蜜爱上我2017-06-12 09:34:47

    Determine the id based on the address of the router

    reply
    0
  • Cancelreply