Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我不想使用 Switch,因为我想利用多个组件使用当前 url 来更新自己。但我必须使用 Switch,因为我想要一个 404 页面。
当然,我使用的是 react-router v4。任何人都可以指出我的解决方案吗?
您可以将路由嵌套在另一个路由组件中
<Switch> <Route component={Main} path="/"/> <Redirect component={404} /> </Switch>
然后在主组件里面
<Route component={Compp1} path="/"/> <Route component={Compp2} path="/"/>