Send props to react component from redirect

Viewed 490

I have a React component in which i'm making a redirect

return <Redirect to={{
        pathname: '/questions',
        state: { open: true }
        }}/>;

I need to access this state in the questions component, and i'm trying so with this.state.location.open which returns undefined. Am i missing some import statement, or am i just completly wrong?

1 Answers

you try sending some params (may not be the best solution)

return <Redirect to={{
        pathname: '/questions/data_to_send',

        }}/>;

While receiving in the questions route, you can try this in index.html (of questions route)

{
      path: 'questions/:data_to_receive',<---- HERE 
      getComponent(nextState, cb) {
        System.import('./containers/QuestionsComponent').then((m) => {
          cb(null, m.default)
        })
      }
}

and again in Questions Component, the data can be received as props in QuestionsComponent as,

this.props.routeParams.data_to_send
Related