美文网首页工作生活
react router 答疑

react router 答疑

作者: 邹小邹大厨 | 来源:发表于2019-07-10 13:03 被阅读0次

exact 作用?

exact 为true的时候,也就是你的url必须和location.pathname 一致,才会匹配。

match.url 和match.path 有什么区别?

观察路由"/users/:userId"
此例中,match.path的返回值将是 "/users/:userId"。
而match.url 的返回值将是:userId的值,例如"users/5"。
请注意上面官方描述中,match.path指用于匹配的模式部分,代表了一种格式,而match.url代表一个具体的计算后的路径表达值。
match.path 用于Router,match.url 通常用于Link

使用fucntion在router的比较好的方式?

good!

<Route
        path="/about"
        render={props => <About {...props} extra={someVariable} />}
      />

bad!

<Route
        path="/contact"
        component={props => <Contact {...props} extra={someVariable} />}
      />

相关文章

网友评论

    本文标题:react router 答疑

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