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

前端 未结 1 1748
太阳男子
太阳男子 2021-02-13 06:59

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:48

    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)
提交回复
热议问题