【发布时间】:2022-01-03 10:59:47
【问题描述】:
我正在制作一个搜索引擎,并希望路由一个数组路径来呈现结果组件。 React Router v5 的代码是这样的:
<Switch>
<Route exact path={["/search", "/images", "/news", "/videos"]}>
<Results />
</Route>
</Switch>
v6 兼容的语法是什么?我尝试了以下方法,但它不起作用:
<Routes>
<Route path={["/search", "/images", "/news", "/videos"]} element={<Results />} />
</Routes>
我当然已经导入了 Routes 和 Route import { Routes, Route} from "react-router-dom";。
【问题讨论】:
标签: reactjs react-router