首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react-router-component深度链接。有可能吗?

react-router-component深度链接。有可能吗?
EN

Stack Overflow用户
提问于 2016-02-14 06:14:00
回答 1查看 507关注 0票数 0

我在使用react-router-component时遇到了一些麻烦。

下面的代码可以很好地工作,至少对于像http://localhost:8080/#about这样的链接:

代码语言:javascript
复制
var App = React.createClass({
  render: function() {
    return (
      <Locations hash>
        <Location path="/" handler={IndexPage} />
        <Location path="/good(/*)" handler={GoodPage} />
        <Location path="/about(/*)" handler={AboutPage} />
        <NotFound handler={NotFoundPage} />
      </Locations>
    )
  }
})

是否有可能像下一个那样实现更深层次的路径处理:

代码语言:javascript
复制
http://localhost:8080/#about/insurance 

文档中没有关于该问题的示例。

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2016-02-14 16:02:53

我在文档里找到了答案。

我们只需要创建带有位置的嵌套组件。

代码语言:javascript
复制
var Sidebar = React.createClass({

  render: function() {
    return (
      <Locations>
        <Location path="/" handler={MainSidebar} />
        <Location path="/users/:username" handler={UserSidebar} />
      </Locations>
    )
  }
})

var Content = React.createClass({

  render: function() {
    return (
      <Locations>
        <Location path="/" handler={MainContent} />
        <Location path="/users/:username" handler={UserContent} />
      </Locations>
    )
  }
})

Then combine them into a single component:

var App = React.createClass({

  render: function() {
    return (
      <div>
        <Sidebar />
        <Content />
      </div>
    )
  }
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35385951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档