加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – 在React Route中使用绝对路径或相对路径

发布时间:2020-12-15 05:03:54 所属栏目:百科 来源:网络整理
导读:所有: 当我在第7课按照其官方教程时,我对React Router很新: https://github.com/reactjs/react-router-tutorial/tree/master/lessons/07-more-nesting 路线参数如: // index.js// ...Route path="/repos" component={Repos} Route path="/repos/:userName
所有:

当我在第7课按照其官方教程时,我对React Router很新:

https://github.com/reactjs/react-router-tutorial/tree/master/lessons/07-more-nesting

路线参数如:

// index.js
// ...
<Route path="/repos" component={Repos}>
  <Route path="/repos/:userName/:repoName" component={Repo}/>
</Route>

它开始使用绝对路径,我想知道:

[1] React-Router如何决定使用abosulte路径或相对路径,只是因为路径以斜杠“/”开头(我发现的一件事是:一旦我在开头添加斜线到相对路径,无论父路由是什么,路径都会变成绝对路径.)?

[2]有没有办法可以使用相对params路径?如果没有,那么路径为“/ repos”的父路由点是什么?

谢谢

> React路由器当前使用绝对路径,but they are working on relative routes
>如果你想要相对路线,看起来人们从匹配参数获取当前路线,然后为其添加路线.例如,< Route path = {match.path'/ more / stuff'} />

在您给出的示例中,重点是每当当前路径包含/ repos时,将会显示一些内容(由component = {Repos}生成的repos链接列表).当路径为/ repos /:userName /:repoName时,它将继续显示该内容,因为路径仍匹配/ repos,但它也将显示特定repo的内容(component = {Repo}).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读