upgrade to fit react-router@1.0.0-rc1

This commit is contained in:
afc163 2015-09-15 17:35:22 +08:00
parent 55a028ba71
commit 961a679a9f
5 changed files with 38 additions and 15 deletions

View File

@ -2,13 +2,12 @@
- order: 2
`react-router@1.0.0-beta3` 进行结合使用。
`react-router@1.x` 进行结合使用。
---
````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;
@ -37,13 +36,13 @@ var Home = React.createClass({
paddingBottom: 15,
borderBottom: '1px dashed #ccc'
}}>点击上面的导航切换页面,面包屑在下面:</div>
<Breadcrumb router={ReactRouter} />
<Breadcrumb {...this.props} router={ReactRouter} />
</div>);
}
});
React.render((
<Router history={history}>
<Router>
<Route name="home" breadcrumbName="首页" path="/" component={Home} ignoreScrollBehavior>
<Route name="apps" breadcrumbName="应用列表" path="apps" component={Apps}>
<Route name="app" breadcrumbName="应用:id" path=":id" />

View File

@ -18,27 +18,27 @@ let BreadcrumbItem = React.createClass({
let Breadcrumb = React.createClass({
propTypes: {
router: React.PropTypes.object
},
contextTypes: {
router: React.PropTypes.object
router: React.PropTypes.object,
routes: React.PropTypes.array,
params: React.PropTypes.object
},
render() {
let crumbs, routes, params;
let crumbs;
let ReactRouter = this.props.router;
if (this.context.router && ReactRouter) {
let routes = this.props.routes;
let params = this.props.params;
if (routes && routes.length > 0 && ReactRouter) {
let Link = ReactRouter.Link;
routes = this.context.router.state.branch;
params = this.context.router.state.params;
crumbs = routes.map(function(route, i) {
let name = route.breadcrumbName.replace(/\:(.*)/g, function(replacement, key) {
return params[key] || replacement;
});
let link;
let path = route.path.indexOf('/') === 0 ? route.path : ('/' + route.path);
if (i === routes.length - 1) {
link = <span>{name}</span>;
} else {
link = <Link to={route.path} params={params}>{name}</Link>;
link = <Link to={path} params={params}>{name}</Link>;
}
return <BreadcrumbItem key={name}>{link}</BreadcrumbItem>;
});

View File

@ -13,3 +13,28 @@
- 当系统拥有超过两级以上的层级结构时;
- 当需要告知用户“你在哪里”时;
- 当需要向上导航的功能时。
## API
```html
<Breadcrumb>
<Breadcrumb.Item>首页</Breadcrumb.Item>
<Breadcrumb.Item href="">应用中心</Breadcrumb.Item>
<Breadcrumb.Item href="">应用列表</Breadcrumb.Item>
<Breadcrumb.Item>某应用</Breadcrumb.Item>
</Breadcrumb>
```
### Breadcrumb
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|-----------|------------------------------------------|------------|---------|--------|
| router | 可传入 react-router 的实例 | Object | | - |
| routes | router 的路由栈信息 | Array | | - |
| params | 路由的参数 | Object | | - |
### Breadcrumb.Item
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|-----------|------------------------------------------|------------|---------|--------|
| href | 链接,如不传则不可点击 | string | | - |

View File

@ -87,7 +87,7 @@
"lodash": "^3.10.0",
"nico-jsx": "~0.5.8",
"precommit-hook": "^1.0.7",
"react-router": "1.0.0-beta3",
"react-router": "1.0.0-rc1",
"webpack": "^1.10.1",
"webpack-dev-middleware": "^1.2.0"
},

View File

@ -1,6 +1,5 @@
window['css-animation'] = require('css-animation');
window['react-router'] = require('react-router');
window['react-router']['HashHistory'] = require('react-router/lib/HashHistory');
var antd = require('antd');
var $ = require('jquery');