【发布时间】:2017-04-25 12:48:43
【问题描述】:
我在我的一个项目中使用react-toolbox。
应用结构
App
--Navigation
--Content
App
应用组件
<div>
<HomeNav />
{this.props.children}
</div>
HomeNav 组件
import { Link } from 'react-router';
...
<Navigation type="horizontal">
<Link to="animals">Animals</Link>
<Link to="plants">Plants</Link>
</Navigation>
注意:Link 导入自 react-router
路线
<Route path="/" component={App}>
<IndexRedirect to="/animals" />
<Route path="animals" component={AnimalsPage} />
<Route path="plants" component={PlantsPage} />
</Route>
按预期工作正常;在路由之间切换时仅刷新Content。但是当我使用react-toolbox中的Link组件时,整个页面正在刷新。
import { Link } from 'react-toolbox/lib/link';
...
<Navigation type="horizontal">
<Link
active
href="animals"
label="Animals"
/>
<Link
href="plants"
label="Plants"
/>
</Navigation>
有没有办法改变这种行为?
在react-toolbox 文档中,# 用于路由(#/components/link)。但是我在路由中使用# 有限制。
【问题讨论】:
-
一个链接负责导航。如果您不能使用哈希路由,则需要拦截链接点击并执行
event.stopPropagation()或使用 Link 以外的其他方式。
标签: reactjs react-toolbox