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

后端 未结 3 2040
花落未央
花落未央 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:36

    This has been updated if you are working with the react-router > v11.0.

    You can read the details here

    TLDR:

     // v0.11.x
     var Something = React.createClass({
       mixins: [ Router.State ],
       render: function () {
          var path = this.getPath();
       }
     });
    

    For the full State API: https://github.com/rackt/react-router/blob/master/doc/04%20Mixins/State.md

提交回复
热议问题