How to update ReactJS component based on URL / path with React-Router

后端 未结 3 2009
花落未央
花落未央 2021-02-05 07:11

How can I update a ReactJS component based on URL / path when using React-Router?

The code below works, but is this the correct way to do this? Seems like a lot of code

3条回答
  •  被撕碎了的回忆
    2021-02-05 07:27

    In react-router 2.0.0 you can use the hashHistory or browserHistory:

    browserHistory.listen(function(ev) {
      console.log('listen', ev.pathname);
    });
    
    {routes}
    

提交回复
热议问题