为每个reactJS组件添加组件
Add component to every reactJS component
我想把导航栏放在所有页面的顶部。这是路由器:
App = React.createClass({
render: function() {
<div>
<NavBar />
<Locations hash className="Router">
<Location path="/" handler={MainPage} />
<Location path="/help" handler={HelpPage} />
<Location path="/about" handler={AboutPage} />
<NotFound handler={NotFoundPage} />
</Locations>
</div>
}
});
注意Locations
标签中的哈希参数。当我这样使用路由器时,<NavBar />
组件中的链接不使用哈希。但是,如果我在每个单独的组件中包含<NavBar />
,那么哈希链接就会像预期的那样工作。是否有一个地方可以包含<NavBar />
,以便它在路由器显示的所有页面上呈现?
通过将router从react-router-component切换为react-router解决。
var App = React.createClass({
render: function() {
return (
<div>
<NavBar />
{this.props.activeRouteHandler}
</div>
);
}
});
React.renderComponent((
<Route handler={App}>
<Route name="main" path="/" handler={MainPage}/>
<Route name="help" handler={HelpPage}/>
<Route name="about" handler={AboutPage}/>
<Route name="notfound" path="*" handler={NotFoundPage}/>
</Route>
), document.body);
相关文章:
- 如何定义组件添加到DataItem的顺序
- React:向现有组件添加道具
- 向React中的高阶组件添加方法
- 在 React 中向组件添加新输入并跟踪状态
- Angular2 - 尝试将组件从父组件添加到子组件中
- extjs4 - 将自定义组件添加到容器
- 将react组件添加到contenteditable或innerhtml
- 反应多个组件添加项目
- 如何向 ReactJS 组件添加多个类
- 可以't将组件添加到dojox/layout/GridContainer
- KnockoutJs组件-添加默认类
- 如何使用React.js而不是JQuery.js克隆React组件(添加到其他地方)
- 向动态创建的组件添加事件绑定
- 如何在rteplugins下为richtext组件添加图像插件
- 为每个reactJS组件添加组件
- 如何向父窗口的组件添加字符
- React:如何给库中的组件添加一个props
- Highcharts提示?如何向hiccharts DOM组件添加类或id ?
- 用于向组件添加多个订阅的React mixin
- 如何在vue.js中为动态组件添加道具