react router 答疑

529 阅读1分钟

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} />}
      />