2015-07-02 17:22:26 +08:00
|
|
|
# 路由
|
|
|
|
|
|
|
|
- order: 2
|
|
|
|
|
2015-09-15 17:35:22 +08:00
|
|
|
和 `react-router@1.x` 进行结合使用。
|
2015-07-02 17:22:26 +08:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
````jsx
|
2015-10-28 20:55:49 +08:00
|
|
|
const ReactRouter = require('react-router');
|
|
|
|
let { Router, Route, Link } = ReactRouter;
|
|
|
|
import { Breadcrumb } from 'antd';
|
2015-07-02 17:22:26 +08:00
|
|
|
|
2015-10-28 20:55:49 +08:00
|
|
|
const Apps = React.createClass({
|
2015-07-02 18:05:34 +08:00
|
|
|
render() {
|
|
|
|
return <ul className="app-list">
|
|
|
|
<li><Link to="/apps/1">应用1</Link></li>
|
|
|
|
<li><Link to="/apps/2">应用2</Link></li>
|
|
|
|
</ul>;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-28 20:55:49 +08:00
|
|
|
const Home = React.createClass({
|
2015-07-02 17:22:26 +08:00
|
|
|
render() {
|
|
|
|
return (<div>
|
|
|
|
<div className="demo-nav">
|
|
|
|
<Link to="/">首页</Link>
|
2015-07-02 18:05:34 +08:00
|
|
|
<Link to="/apps">应用列表</Link>
|
2015-07-02 17:22:26 +08:00
|
|
|
</div>
|
2015-08-20 19:52:56 +08:00
|
|
|
{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>
|
2015-09-15 17:35:22 +08:00
|
|
|
<Breadcrumb {...this.props} router={ReactRouter} />
|
2015-07-02 17:22:26 +08:00
|
|
|
</div>);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-20 16:47:55 +08:00
|
|
|
ReactDOM.render((
|
2015-09-15 17:35:22 +08:00
|
|
|
<Router>
|
2015-12-07 11:19:08 +08:00
|
|
|
<Route name="home" breadcrumbName="首页" path="/" component={Home}>
|
2015-08-21 16:41:39 +08:00
|
|
|
<Route name="apps" breadcrumbName="应用列表" path="apps" component={Apps}>
|
|
|
|
<Route name="app" breadcrumbName="应用:id" path=":id" />
|
2015-08-20 19:52:56 +08:00
|
|
|
</Route>
|
2015-07-02 18:05:34 +08:00
|
|
|
</Route>
|
2015-08-20 19:52:56 +08:00
|
|
|
</Router>
|
2015-12-29 12:08:58 +08:00
|
|
|
), mountNode);
|
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;
|
2015-07-02 18:05:34 +08:00
|
|
|
padding: 0 10px;
|
|
|
|
}
|
|
|
|
.app-list {
|
|
|
|
margin-top: 15px;
|
2015-07-02 17:22:26 +08:00
|
|
|
}
|
|
|
|
</style>
|