React路由器路径语法混乱
React router path syntax confusion
有人可以解释一下为什么在将斜杠应用于子路径时找不到子路径
<Route path=":paramName1">
...
<Route path="/:paramName2" component={Child} />
</Route>
然而,当斜杠应用于父路径时是否成功?
<Route path=":paramName1(/)">
...
<Route path=":paramName2" component={Child} />
</Route>
举一个更简单的例子,如果你这样做
<Route path="/foo" component={Parent}>
<Route path="/bar" component={Child} />
</Route>
Child
的路径实际上是 /bar
,而不是 /foo/bar
。
在你的情况下,你只需要
<Route path="/:foo" component={Parent}>
<Route path=":bar" component={Child} />
</Route>
为 Child
获得 /:foo/:bar
。
有人可以解释一下为什么在将斜杠应用于子路径时找不到子路径
<Route path=":paramName1">
...
<Route path="/:paramName2" component={Child} />
</Route>
然而,当斜杠应用于父路径时是否成功?
<Route path=":paramName1(/)">
...
<Route path=":paramName2" component={Child} />
</Route>
举一个更简单的例子,如果你这样做
<Route path="/foo" component={Parent}>
<Route path="/bar" component={Child} />
</Route>
Child
的路径实际上是 /bar
,而不是 /foo/bar
。
在你的情况下,你只需要
<Route path="/:foo" component={Parent}>
<Route path=":bar" component={Child} />
</Route>
为 Child
获得 /:foo/:bar
。