我正在使用 React Router v5,我想知道如何在一条路径中同时匹配
/add_a
和 /add
。
我已经尝试过
<Route path="/add*" element={<div>TEST</div>} />
,但我收到警告 Route path "/add*" will be treated as if it were "/add/*"
。
<Routes>
<Route path="/add*" element={<div>TEST</div>} />
</Routes>
参考: https://v5.reactrouter.com/web/api/Route/path-string-string
试试这个
/add[^/]+
这将匹配除第二个“/”之外的所有内容
这意味着
/add_somethinghere
匹配
但是
/add_somethinghere/extrathing
不匹配
尝试这里的游乐场https://forbeslindesay.github.io/express-route-tester/