gpt4 book ai didi

javascript - 在react-router路由中使splat可选

转载 作者:太空宇宙 更新时间:2023-11-04 16:09:20 24 4
gpt4 key购买 nike

所以目前,我想要一个可以是任何 ids 枚举的路由(有点像文件浏览器)。它看起来像这样:

<Route path="/browser">
<IndexRoute component={FileBrowser} />
<Route path=":id">
<IndexRoute component={HardDriveBrowser} />
<Route path="folders/**/:folderId" component={FolderContents} />
</Route>
</Route>

但是,如果我访问诸如 /browser/1/folders/2 之类的路线,则它不匹配。我认为它正在等待撞击声。

有没有办法将 splat 指定为可选,或者将其默认为空字符串?

最佳答案

在react-router v4中,只需将?放在末尾即可使参数可选。在react-router v2中,您可以使用括号使参数成为可选参数。例如:(:folderId) 将使该选项成为可选。

关于javascript - 在react-router路由中使splat可选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41639079/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com