用负前瞻反应路由器

spo*_*bob 4 react-router

基本上我想抓住<Route path="/:slug" />但除了/not-found. 我尝试使用看起来像/:slug(^(?!.*not-found).*$)但它不起作用的路径到正则表达式的自定义匹配参数。它在这里不起作用http://forbeslindesay.github.io/express-route-tester/,但它在https://regex101.com/中起作用

我想知道当我试图捕捉时如何排除路径/:slug

hey*_*ugo 5

我在 path-to-regex repo 中发现了这个问题,说这不受支持,但使用 RegEx 是。但是 react-router目前只支持 path as string 。

此外,您可以在此演示中测试路径到正则表达式的匹配

因此,要获得这种行为,我认为要走的路是查看组件渲染的matchorlocation道具,<Route path="/:slug" />并有条件地渲染未找到的组件。