react-router 路由跳转遇到的坑

exact 是 route 中的一个属性, 今天在做项目的时候,发现自己写的Link跳转,一直跳的都是首页 - -!!, 还郁闷了好久,后来突然想起上面的那句话来

   <Route path='/' component={Home} />
   <Route path='/page' component={Page}>

上面这种情况下,如果匹配路由path='/page',因为他们都包含 / 所以当匹配到home时,就不再往下匹配了

一般 exact 用在路由路径比较短的Route 上面; (如下代码)

     <Route exact path='/' component={Home} />
     <Route path='/page' component={Page} />