forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
58 lines (52 loc) · 1.43 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, { Component } from 'react'
import { render } from 'react-dom'
import { browserHistory, Router, Route, Link, Redirect } from 'react-router'
class App extends Component {
render() {
return (
<div>
<ul>
<li><Link to="/user/123" activeClassName="active">Bob</Link></li>
<li><Link to="/user/abc" activeClassName="active">Sally</Link></li>
</ul>
{this.props.children}
</div>
)
}
}
class User extends Component {
render() {
const { userID } = this.props.params
return (
<div className="User">
<h1>User id: {userID}</h1>
<ul>
<li><Link to={`/user/${userID}/tasks/foo`} activeClassName="active">foo task</Link></li>
<li><Link to={`/user/${userID}/tasks/bar`} activeClassName="active">bar task</Link></li>
</ul>
{this.props.children}
</div>
)
}
}
class Task extends Component {
render() {
const { userID, taskID } = this.props.params
return (
<div className="Task">
<h2>User ID: {userID}</h2>
<h3>Task ID: {taskID}</h3>
</div>
)
}
}
render((
<Router history={browserHistory}>
<Route path="/" component={App}>
<Route path="user/:userID" component={User}>
<Route path="tasks/:taskID" component={Task} />
<Redirect from="todos/:taskID" to="tasks/:taskID" />
</Route>
</Route>
</Router>
), document.getElementById('example'))