L
L
lucky42021-03-10 10:48:31
React
lucky4, 2021-03-10 10:48:31

How to pass a link to a separate page?

How to make transition to id-component?

There is a routing:

<BrowserRouter>
          <Switch>
            <Route path="/catalog" component={ CatalogPage } exact />
            <Route path="/products" component={ ProductPage } exact />
            <Route path="/products/:id" component={ ItemPage } exact />
          </Switch>
      </BrowserRouter>


And there is the component itself, through which it will be necessary to go to a separate page (ItemPage):
<Link to="products/:id" style={{ textDecoration: "none", color: "inherit" }}>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Nesterov, 2021-03-10
@lucky4

In the router, you have it right -
path="/products/:id"
And in the Link there should be something like this -
Link to=`products/${id}`
That is, you need to pass the real product id to the Link. For example from props.match.params.id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question