【问题标题】:React-router <Link> not working with data-toggleReact-router <Link> 不适用于数据切换
【发布时间】:2016-03-20 22:07:19
【问题描述】:

我正在尝试使用 React、React-Router 和 bootstrap 来定义基于药丸的导航栏。我这样定义导航栏:

render: function() {
  return (
    <div className="container-fluid">
      <ul className="nav nav-pills">
        <li className="active"><Link data-toggle="tab" to="/test/vocabulary">Vocabulary</Link></li>
        <li><Link data-toggle="tab" to="/test/noun">Noun</Link></li>
      </ul>
      <div className="tab-content">
        <div id="vocabulary" className="tab-pane fade in active">
          <TestVocabularyView/>
        </div>
        <div id="noun" className="tab-pane fade">
          <TestNounView/>
        </div>
      </div>
    </div>
  );
}

我遇到的问题是&lt;Link&gt; 的“数据切换”方面。当我单击药丸标题时,我会在浏览器控制台中看到:

jquery.js:1491 Uncaught Error: Syntax error, unrecognized expression:
#/test/nounSizzle.error @ jquery.js:1491Sizzle.tokenize @
jquery.js:2108Sizzle.select @ jquery.js:2512Sizzle @    
jquery.js:888jQuery.fn.extend.find @ jquery.js:2728jQuery.fn.init @ 
jquery.js:2845jQuery @ jquery.js:73Tab.show @ bootstrap.js:2096(anonymous function) @ bootstrap.js:2169jQuery.extend.each @ 
jquery.js:384jQuery.fn.jQuery.each @ jquery.js:136Plugin @ 
bootstrap.js:2164clickHandler @ bootstrap.js:2193jQuery.event.dispatch @ 
jquery.js:4665elemData.handle @ jquery.js:4333

我的路线是这样设置的:

<Route path="test" component={TestView}>
  <Route path="vocabulary" component={TestVocabularyView}/>
  <Route path="noun" component={TestNounView}/>
</Route>

当我将鼠标悬停在“名词”药丸标题上时,我看到了这个 URL:http://localhost:3000/#/test/noun

我正在使用浏览器历史记录。

【问题讨论】:

标签: twitter-bootstrap react-router


【解决方案1】:

而不是做

<li><Link data-toggle="tab" to="/test/noun">Noun</Link></li>

我这样做了:

<li data-toggle="tab"><Link to="/test/noun">Noun</Link></li>

【讨论】:

    猜你喜欢
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多