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?

vicusbass
  • 1,394
  • 1
  • 15
  • 29
  • 1
    onEnter no longer in react-router https://stackoverflow.com/questions/42768620/onenter-not-called-in-react-router – Derrops Nov 26 '17 at 11:07

1 Answers1

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
}
vicusbass
  • 1,394
  • 1
  • 15
  • 29