【问题标题】:How to create react tabs with fragment identifiers (hash links)?如何使用片段标识符(哈希链接)创建反应选项卡?
【发布时间】:2019-09-30 20:30:03
【问题描述】:

我使用 react-tabs (https://reactcommunity.org/react-tabs/) 创建 4 个标签。现在我需要为他们创建类似“https://example.com/page=01#tab1”、“https://example.com/page=01#tab2”的路线。当您单击选项卡名称时,它们会打开带有所选选项卡的页面。

我尝试用 react-router-dom 中的几个 <Link to="#tab1>Tab1</Link><Route path='#tab1' render={() => <MyComponent store={store}/>}/> 替换 react-tabs,但标签没有切换。

【问题讨论】:

    标签: typescript react-router react-tabs


    【解决方案1】:

    好吧,我只找到了一种解决方案:我使用 window.location.hash 来设置和获取 hashlink 值。此外,我将回调 onMouseDown 添加到选项卡名称以模仿路由器:我在此回调中更改 window.location.href。

    【讨论】:

      猜你喜欢
      • 2011-05-11
      • 1970-01-01
      • 1970-01-01
      • 2017-03-06
      • 2012-07-24
      • 2014-05-13
      • 1970-01-01
      相关资源
      最近更新 更多