React-router - how to use route params in onEnter?

前端 未结 1 759
無奈伤痛
無奈伤痛 2021-02-13 07:18

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



        
相关标签:
1条回答
  • 2021-02-13 07:22

    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
    }
    
    0 讨论(0)
提交回复
热议问题