我使用了三种不同的路线相同的组件:多路径名称阵营路由器
<Router>
<Route path="/home" component={Home} />
<Route path="/users" component={Home} />
<Route path="/widgets" component={Home} />
</Router>
反正是有它结合起来,如:
<Router>
<Route path=["/home", "/users", "/widgets"] component={Home} />
</Router>
好主意@Cameron。我发现修改它有点有用,只匹配以一个组开头的路径:'/^\ /(home | users | widgets)/'现在,'/ widgets'会匹配,但是'/ dashboard/widgets '不匹配。 – Towler
应该很好,但现在类型正则表达式在prop-types验证中是无效的:'警告:失败的道具类型:''regexp'类型的道路'无效'提供给'Route',期望的'字符串'。' –
@FábioPaiva是啊,我还没有想出如何在路线中放置一个任意的正则表达式 – Atav32