react-router注意点

161 阅读1分钟

一、自顶向下匹配的路由算法

    <Route path="/currentJourney" component={CurrentJourney} exact={true} />
    <Redirect from="/historyJourney" to='/currentJourney' />
    <Route path="/historyJourney" component={HistoryJourney} exact={true} />

这样写在跳转 /historyJourney 的时候,会立马在跳转到 /currentJourney 去。


    <Route path="/currentJourney" component={CurrentJourney} exact={true} />
    <Route path="/historyJourney" component={HistoryJourney} exact={true} />
    <Redirect from="/historyJourney" to='/currentJourney' />

跳转 /historyJourney 的时候,不会跳转到 /currentJourney去。

这是因为react-router路由算法是自顶向下匹配路由的。在匹配到后就就会停止。