【发布时间】: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>
);
}
我遇到的问题是<Link> 的“数据切换”方面。当我单击药丸标题时,我会在浏览器控制台中看到:
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
我正在使用浏览器历史记录。
【问题讨论】:
-
我认为你不能像那样插入 Bootstrap。你试过React-Bootstrap之类的吗?
-
我最终的“解决方案”:我没有尝试路由到各个选项卡,而是使用 onClick 函数来选项卡(“显示”)适当的选项卡。这可以正常工作,但代价是无法通过 URL 访问选项卡窗格。
-
查看引导代码,我发现它专门寻找 标记。所以特殊的 React-Router 标签肯定是问题的一部分。
标签: twitter-bootstrap react-router