M
M
maksmaksimovich2018-09-01 13:09:09
React
maksmaksimovich, 2018-09-01 13:09:09

How to pass data to components using a router?

I understand with react, I have several components on the main page, I pass data to them like this.
<myComponent data={this.state.data} />
I decided to add a router to the page
, it turned out something like this

<Router>
        <Fragment>
          <Menu />
          <Route exact path='/component' component={myComponent} />
          <Route path='/another-component' component={mySecondComponent} />
        </Fragment>
      </Router>

This head component stores the state, how now to pass data to these components from it?
And also how to make it so that when loading it goes directly to the '/component' page, and not to '/'?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2018-09-01
@maksmaksimovich

how now to pass data to these components from it?
<Route exact path='/component' render={() => <myComponent prop={value}/>} />

I understand that this is convenient when others think for you, but you still try to read the documentation: https://reacttraining.com/react-router/
I myself just started working with this library yesterday and, as you can see, I was quite able to answer to these questions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question