14

I want to do a fetch using the onEnter callback, but I don't know how to read a URL param in the Route component. I have this Route

<Route path="book/:bookId" component={BookContainer} onEnter={onBookLoad()}/>

I want to use the bookId from path as function parameter for onBookLoad(). Is it possible?

1

1 Answer 1

21

Nevermind, it was trivial.

<Route path="book/:bookId" component={BookContainer} onEnter={onBookLoad}/>

export function onBookLoad(nextState) {
 console.log(nextState.params.bookId);
 //do stuff with the param
}
1
  • 1
    Do you mean bookId, not surveyId?
    – Aaron_H
    May 13, 2016 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.