Skip to content

Commit 1a2798b

Browse files
hegdeashwintimdorr
authored andcommitted
Adds example to show "page not found" implementation (#3251)
* Adds example to show "page not found" implementation * Fixes build #3263 failed
1 parent e3e1545 commit 1a2798b

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

examples/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ <h1>React Router Examples</h1>
1717
<li><a href="passing-props-to-children">Passing Props to Children</a></li>
1818
<li><a href="pinterest">Pinterest-style UI (<code>location.state</code>)</a></li>
1919
<li><a href="query-params">Query Params</a></li>
20+
<li><a href="route-no-match">Route Not Found</a></li>
2021
<li><a href="sidebar">Sidebar</a></li>
2122
</ul>

examples/route-no-match/app.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react'
2+
import { render } from 'react-dom'
3+
import { browserHistory, Router, Route, Link } from 'react-router'
4+
5+
class User extends React.Component {
6+
render() {
7+
let { userID } = this.props.params
8+
let { query } = this.props.location
9+
let age = query && query.showAge ? '33' : ''
10+
11+
return (
12+
<div className="User">
13+
<h1>User id: {userID}</h1>
14+
{age}
15+
</div>
16+
)
17+
}
18+
}
19+
20+
class App extends React.Component {
21+
render() {
22+
return (
23+
<div>
24+
<ul>
25+
<li><Link to="/user/bob" activeClassName="active">Bob</Link></li>
26+
<li><Link to={{ pathname: '/user/bob', query: { showAge: true } }} activeClassName="active">Bob With Query Params</Link></li>
27+
<li><Link to="/user/sally" activeClassName="active">Sally</Link></li>
28+
</ul>
29+
{this.props.children}
30+
</div>
31+
)
32+
}
33+
}
34+
35+
class PageNotFound extends React.Component {
36+
render() {
37+
return (
38+
<div>
39+
<h1>Page Not Found.</h1>
40+
<p>Go to <Link to="/">Home Page</Link></p>
41+
</div>
42+
)
43+
}
44+
}
45+
46+
render((
47+
<Router history={browserHistory}>
48+
<Route path="/" component={App}>
49+
<Route path="user/:userID" component={User} />
50+
</Route>
51+
<Route path="*" component={PageNotFound} />
52+
</Router>
53+
), document.getElementById('example'))

examples/route-no-match/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>Route Not Found Example</title>
3+
<base href="/route-no-match"/>
4+
<link href="/global.css" rel="stylesheet"/>
5+
<body>
6+
<h1 class="breadcrumbs"><a href="/">React Router Examples</a> / Route Not Found</h1>
7+
<div id="example"/>
8+
<script src="/__build__/shared.js"></script>
9+
<script src="/__build__/route-no-match.js"></script>

0 commit comments

Comments
 (0)