【发布时间】:2021-04-29 17:55:15
【问题描述】:
使用react-router-dom 5.2.0 获得价值。
根据习惯,我倾向于将所有 Route 组件包裹在 Switch 组件中。
例子:
const MyRoutes = () => (
<Switch>
<Route
path='/route1'
exact
component={() => <Route1Component />}
/>
<Route
path={[
'/route2',
'/route2/subroute',
'/route2/subroute2',
]}
exact
component={() => <Route2Component />}
/>
<Route
path='*'
exact
component={() => <OtherRoutesComponent />}
/>
</Switch>
)
但我已经意识到,没有它工作没有任何区别。
所以我的问题是,为什么要全部使用它?它有什么好处或坏处吗?
【问题讨论】:
标签: javascript reactjs react-router react-router-dom