2015-07-02 17:22:26 +08:00
|
|
|
# 路由
|
|
|
|
|
|
|
|
- order: 2
|
|
|
|
|
|
|
|
和 `react-router@0.13.x` 进行结合使用。
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
````jsx
|
2015-07-06 20:18:19 +08:00
|
|
|
var Router = require('react-router');
|
2015-07-02 17:22:26 +08:00
|
|
|
var Route = Router.Route;
|
|
|
|
var Link = Router.Link;
|
|
|
|
var RouteHandler = Router.RouteHandler;
|
2015-07-06 20:18:19 +08:00
|
|
|
var Breadcrumb = require('antd/lib/breadcrumb');
|
2015-07-02 17:22:26 +08:00
|
|
|
|
2015-07-02 18:05:34 +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>;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-02 17:22:26 +08:00
|
|
|
var App = React.createClass({
|
|
|
|
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-07-02 21:58:04 +08:00
|
|
|
<Breadcrumb Router={Router} />
|
2015-07-02 17:22:26 +08:00
|
|
|
<RouteHandler />
|
|
|
|
</div>);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var routes = (
|
|
|
|
<Route name="首页" path="/" handler={App} ignoreScrollBehavior>
|
2015-07-02 18:05:34 +08:00
|
|
|
<Route name="应用列表" path="/apps" handler={Apps}>
|
|
|
|
<Route name="应用:id" path="/apps/:id" handler={App} />
|
|
|
|
</Route>
|
2015-07-02 17:22:26 +08:00
|
|
|
</Route>
|
|
|
|
);
|
|
|
|
|
|
|
|
Router.run(routes, Router.HashLocation, (Root) => {
|
|
|
|
React.render(<Root />, document.getElementById('components-breadcrumb-demo-router'));
|
|
|
|
});
|
|
|
|
````
|
|
|
|
|
|
|
|
<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>
|