2017-04-06 14:10:01 +08:00
|
|
|
|
---
|
|
|
|
|
order: 3
|
|
|
|
|
iframe: 200
|
|
|
|
|
reactRouter: react-router-dom
|
|
|
|
|
title:
|
2017-06-16 14:57:14 +08:00
|
|
|
|
zh-CN: 其它路由
|
|
|
|
|
en-US: Other Router Integration
|
2017-04-06 14:10:01 +08:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
2017-06-16 14:57:14 +08:00
|
|
|
|
和 `react-router@4`,或其他路由进行结合使用。
|
2017-04-06 14:10:01 +08:00
|
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
2017-06-16 14:57:14 +08:00
|
|
|
|
Used together with `react-router@4` or other router.
|
2017-04-06 14:10:01 +08:00
|
|
|
|
|
|
|
|
|
````jsx
|
2017-06-16 14:57:14 +08:00
|
|
|
|
import { HashRouter as Router, Route, Switch, Link, withRouter } from 'react-router-dom';
|
2017-04-06 14:10:01 +08:00
|
|
|
|
import { Breadcrumb, Alert } from 'antd';
|
|
|
|
|
|
|
|
|
|
const Apps = () => (
|
|
|
|
|
<ul className="app-list">
|
|
|
|
|
<li>
|
|
|
|
|
<Link to="/apps/1">Application1</Link>:<Link to="/apps/1/detail">Detail</Link>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<Link to="/apps/2">Application2</Link>:<Link to="/apps/2/detail">Detail</Link>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
);
|
|
|
|
|
|
2017-06-16 14:57:14 +08:00
|
|
|
|
const breadcrumbNameMap = {
|
|
|
|
|
'/apps': 'Application List',
|
|
|
|
|
'/apps/1': 'Application1',
|
|
|
|
|
'/apps/2': 'Application2',
|
|
|
|
|
'/apps/1/detail': 'Detail',
|
|
|
|
|
'/apps/2/detail': 'Detail',
|
|
|
|
|
};
|
|
|
|
|
const Home = withRouter((props) => {
|
|
|
|
|
const { location } = props;
|
|
|
|
|
const pathSnippets = location.pathname.split('/').filter(i => i);
|
|
|
|
|
const extraBreadcrumbItems = pathSnippets.map((_, index) => {
|
|
|
|
|
const url = `/${pathSnippets.slice(0, index + 1).join('/')}`;
|
|
|
|
|
return (
|
|
|
|
|
<Breadcrumb.Item key={url}>
|
|
|
|
|
<Link to={url}>
|
|
|
|
|
{breadcrumbNameMap[url]}
|
|
|
|
|
</Link>
|
|
|
|
|
</Breadcrumb.Item>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
const breadcrumbItems = [(
|
|
|
|
|
<Breadcrumb.Item key="home">
|
2017-04-06 14:10:01 +08:00
|
|
|
|
<Link to="/">Home</Link>
|
2017-06-16 14:57:14 +08:00
|
|
|
|
</Breadcrumb.Item>
|
|
|
|
|
)].concat(extraBreadcrumbItems);
|
|
|
|
|
return (
|
|
|
|
|
<div className="demo">
|
|
|
|
|
<div className="demo-nav">
|
|
|
|
|
<Link to="/">Home</Link>
|
|
|
|
|
<Link to="/apps">Application List</Link>
|
|
|
|
|
</div>
|
|
|
|
|
<Switch>
|
|
|
|
|
<Route path="/apps" component={Apps} />
|
|
|
|
|
<Route render={() => <span>Home Page</span>} />
|
|
|
|
|
</Switch>
|
|
|
|
|
<Alert style={{ margin: '16px 0' }} message="Click the navigation above to switch:" />
|
|
|
|
|
<Breadcrumb>
|
|
|
|
|
{breadcrumbItems}
|
|
|
|
|
</Breadcrumb>
|
2017-04-06 14:10:01 +08:00
|
|
|
|
</div>
|
2017-06-16 14:57:14 +08:00
|
|
|
|
);
|
|
|
|
|
});
|
2017-04-06 14:10:01 +08:00
|
|
|
|
|
|
|
|
|
ReactDOM.render(
|
|
|
|
|
<Router>
|
2017-06-16 14:57:14 +08:00
|
|
|
|
<Home />
|
2017-04-06 14:10:01 +08:00
|
|
|
|
</Router>
|
|
|
|
|
, mountNode);
|
|
|
|
|
````
|
|
|
|
|
|
|
|
|
|
````css
|
|
|
|
|
.demo {
|
|
|
|
|
margin: 16px;
|
|
|
|
|
}
|
|
|
|
|
.demo-nav {
|
|
|
|
|
height: 30px;
|
|
|
|
|
line-height: 30px;
|
|
|
|
|
margin-bottom: 16px;
|
|
|
|
|
background: #f8f8f8;
|
|
|
|
|
}
|
|
|
|
|
.demo-nav a {
|
|
|
|
|
line-height: 30px;
|
|
|
|
|
padding: 0 8px;
|
|
|
|
|
}
|
|
|
|
|
.app-list {
|
|
|
|
|
margin-top: 16px;
|
|
|
|
|
}
|
|
|
|
|
````
|