Skip to content

Commit cf683fc

Browse files
committed
Merge pull request #2151 from grabbou/feature/breadcrumbs-example
Breadcrumbs example
2 parents 147240f + 0152809 commit cf683fc

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed

examples/breadcrumbs/app.css

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
aside {
2+
position: absolute;
3+
left: 0;
4+
width: 300px;
5+
}
6+
7+
main {
8+
position: absolute;
9+
left: 310px;
10+
}
11+
12+
ul.breadcrumbs-list {
13+
margin: 0;
14+
padding: 0;
15+
}
16+
17+
ul.breadcrumbs-list li {
18+
display: inline-block;
19+
margin-right: 20px;
20+
}
21+
22+
ul.breadcrumbs-list li a:not(.breadcrumb-active) {
23+
font-weight: bold;
24+
margin-right: 20px;
25+
}
26+
27+
ul.breadcrumbs-list li a.breadcrumb-active {
28+
text-decoration: none;
29+
cursor: default;
30+
}

examples/breadcrumbs/app.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import React from 'react/addons'
2+
import { createHistory, useBasename } from 'history'
3+
import { Router, Route, Link } from 'react-router'
4+
5+
require('./app.css')
6+
7+
const history = useBasename(createHistory)({
8+
basename: '/breadcrumbs'
9+
})
10+
11+
class App extends React.Component {
12+
static title = 'Home';
13+
static path = '/';
14+
15+
render() {
16+
const depth = this.props.routes.length
17+
18+
return (
19+
<div>
20+
<aside>
21+
<ul>
22+
<li><Link to={Products.path}>Products</Link></li>
23+
<li><Link to={Orders.path}>Orders</Link></li>
24+
</ul>
25+
</aside>
26+
<main>
27+
<ul className="breadcrumbs-list">
28+
{this.props.routes.map((item, index) =>
29+
<li key={index}>
30+
<Link
31+
onlyActiveOnIndex={true}
32+
activeClassName="breadcrumb-active"
33+
to={item.path || ''}>
34+
{item.component.title}
35+
</Link>
36+
{(index + 1) < depth && '\u2192'}
37+
</li>
38+
)}
39+
</ul>
40+
{this.props.children}
41+
</main>
42+
</div>
43+
)
44+
}
45+
}
46+
47+
class Products extends React.Component {
48+
static title = 'Products';
49+
static path = '/products';
50+
51+
render() {
52+
return (
53+
<div className="Page">
54+
<h1>Products</h1>
55+
</div>
56+
)
57+
}
58+
}
59+
60+
class Orders extends React.Component {
61+
static title = 'Orders';
62+
static path = '/orders';
63+
64+
render() {
65+
return (
66+
<div className="Page">
67+
<h1>Orders</h1>
68+
</div>
69+
)
70+
}
71+
}
72+
73+
React.render((
74+
<Router history={history}>
75+
<Route path={App.path} component={App}>
76+
<Route path={Products.path} component={Products} />
77+
<Route path={Orders.path} component={Orders} />
78+
</Route>
79+
</Router>
80+
), document.getElementById('example'))

examples/breadcrumbs/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html public "restroom">
2+
<title>Breadcrumbs Example</title>
3+
<link href="/global.css" rel="stylesheet"/>
4+
<link href="/animations/app.css" rel="stylesheet"/>
5+
<body>
6+
<h1 class="breadcrumbs"><a href="/">React Router Examples</a> / Breadcrumbs</h1>
7+
<div id="example"/>
8+
<script src="/__build__/shared.js"></script>
9+
<script src="/__build__/breadcrumbs.js"></script>

examples/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ <h1>React Router Examples</h1>
77
<li><a href="animations">Animations</a></li>
88
<li><a href="auth-flow">Auth Flow</a></li>
99
<li><a href="auth-with-shared-root">Auth With Shared Root</a></li>
10+
<li><a href="breadcrumbs">Breadcrumbs</a></li>
1011
<li><a href="dynamic-segments">Dynamic Segments</a></li>
1112
<li><a href="huge-apps">Huge Apps (Partial App Loading)</a></li>
1213
<li><a href="master-detail">Master Detail</a></li>

0 commit comments

Comments
 (0)