Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass props through route

In react how can I configure a route to pass props. for example my route.tsx is:

export const routes = () => (
  <Layout>
    <Route exact path='/' component={ Home } />
    <Route path='/counter' component={ Counter } />
    <Route path='/fetchdata' component={ FetchData } />
  </Layout>
);

How can I pass some data as props to my Counter component when ever /counter is evoked

like image 414
Tee F Avatar asked May 22 '18 14:05

Tee F


2 Answers

You can use the render prop.

  <Route 
     path='/counter' 
     render={(props) => (
       <Counter {...props} count={5} />
     )} 
  />
like image 85
Omar Avatar answered Oct 25 '22 14:10

Omar


This will do the work: Render

    <Route
      path='/dashboard'
      render={(props) => <Dashboard {...props} isAuthed={true} />}
    />

Hope this helps!

like image 28
Harshal Y. Avatar answered Oct 25 '22 16:10

Harshal Y.