R
R
raft882018-03-13 03:32:02
React
raft88, 2018-03-13 03:32:02

How to pass props to React-router?

Hey!

<Route
  component={() => logged ? <Product /> : <Redirect to='/' />}
  exact
  path='/products/:id'
/>

with such an entry in the Product component in props, data is lost, as a result, there is no match where you can take the product id. How to rewrite Route so as not to lose props?
with such a record, it works correctly, but there is no check that the user is logged in
<Route
  component={Product}
  exact
  path='/products/:id'
/>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eternalSt, 2018-03-13
@raft88

Good day! The Route
component has a render parameter .

<Route
  render = { props => logged ? <Product /> : <Redirect to='/' /> }
  exact
  path='/products/:id'
/>

And it is important, of course it is said about this in the docks, but I will repeat myself.
component takes precedence over render , so you shouldn't use them together.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question