ant-design/components/breadcrumb/demo/router.md

71 lines
1.6 KiB
Markdown
Raw Normal View History

2015-07-02 17:22:26 +08:00
# 路由
- order: 2
`react-router@1.0.0-beta3` 进行结合使用。
2015-07-02 17:22:26 +08:00
---
````jsx
var ReactRouter = require('react-router');
var history = require('react-router/lib/HashHistory').history;
var Router = ReactRouter.Router;
var Route = ReactRouter.Route;
var Link = ReactRouter.Link;
var Breadcrumb = require('antd').Breadcrumb;
2015-07-02 17:22:26 +08:00
var Apps = React.createClass({
render() {
return <ul className="app-list">
<li><Link to="/apps/1">应用1</Link></li>
<li><Link to="/apps/2">应用2</Link></li>
</ul>;
}
});
var Home = React.createClass({
2015-07-02 17:22:26 +08:00
render() {
return (<div>
<div className="demo-nav">
<Link to="/">首页</Link>
<Link to="/apps">应用列表</Link>
2015-07-02 17:22:26 +08:00
</div>
{this.props.children || 'Home'}
2015-07-17 18:39:33 +08:00
<div style={{
marginBottom: 15,
marginTop: 15,
paddingBottom: 15,
borderBottom: '1px dashed #ccc'
}}>点击上面的导航切换页面,面包屑在下面:</div>
<Breadcrumb router={ReactRouter} />
2015-07-02 17:22:26 +08:00
</div>);
}
});
React.render((
<Router history={history}>
2015-08-21 16:41:39 +08:00
<Route name="home" breadcrumbName="首页" path="/" component={Home} ignoreScrollBehavior>
<Route name="apps" breadcrumbName="应用列表" path="apps" component={Apps}>
<Route name="app" breadcrumbName="应用:id" path=":id" />
</Route>
</Route>
</Router>
), document.getElementById('components-breadcrumb-demo-router'));
2015-07-02 17:22:26 +08:00
````
<style>
.demo-nav {
height: 30px;
line-height: 30px;
margin-bottom: 15px;
background: #f8f8f8;
}
.demo-nav a {
line-height: 30px;
padding: 0 10px;
}
.app-list {
margin-top: 15px;
2015-07-02 17:22:26 +08:00
}
</style>