美文网首页
2017.11.21

2017.11.21

作者: 07120665a058 | 来源:发表于2017-11-22 11:25 被阅读21次

    react router v4

    当父子路由嵌套的时候必须写完整路径,如下

    <Route path='/App' component={App} />
    <Route path='/App/task' component={Task} />
    

    不能在父组件里面写相对路径,如下

    const App = ()=>{
      return <div>
            <Route path='/task' component={Task} />
      </div>
    }
    <Route path='/App' component={App} />
    

    this.props 里面有history,location,match等属性,history类似于浏览器窗口中的history对象

    history对象常用属性

    • location (object类型),当前的位置,常用属性有pathname是url路径,search是url中的查询字符串
    • push (function 类型),在 hisotry 栈顶加入一个新的地址
    • replace( function 类型),替换history 堆栈中的当前地址

    相关文章

      网友评论

          本文标题:2017.11.21

          本文链接:https://www.haomeiwen.com/subject/udzwvxtx.html