-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathindex.js
109 lines (97 loc) · 3.01 KB
/
index.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
require('bootstrap/dist/css/bootstrap.min.css')
require('bootstrap/dist/css/bootstrap-theme.min.css')
require('./style.css')
import React from 'react'
import {render} from 'react-dom'
import hashHistory from 'react-router/lib/hashHistory'
import IndexRoute from 'react-router/lib/IndexRoute'
import Route from 'react-router/lib/Route'
import Router from 'react-router/lib/Router'
import activeComponent from '../../src'
let NavItem = activeComponent('li')
let ActivePara = activeComponent('p', {link: false})
let App = React.createClass({
render() {
return <div className="App container">
<nav className="navbar navbar-default" role="navigation">
<div className="container">
<span className="navbar-brand">Example App</span>
<ul className="nav navbar-nav">
<NavItem to="/" onlyActiveOnIndex>Dashboard</NavItem>
<NavItem to="/tasks">Tasks</NavItem>
<li>
<p className="navbar-text"><code><li></code>s in this navbar get the <code>active</code>class</p>
</li>
</ul>
</div>
</nav>
{this.props.children}
<hr/>
<footer>
<a href="https://github.com/insin/react-router-active-component">Fork me on GitHub</a>
</footer>
</div>
}
})
let Dashboard = React.createClass({
render() {
return <div className="Dashboard">
<h2>Dashboard</h2>
<p>I'm a regular paragraph.</p>
<ActivePara to="/" activeClassName="special" onlyActiveOnIndex>
I get highlighted because the Dashboard route is active.
</ActivePara>
</div>
}
})
let Tasks = React.createClass({
render() {
return <div className="Tasks row">
<div className="col-md-3">
<ul className="nav nav-pills nav-stacked">
<NavItem to="/tasks/all">All Tasks</NavItem>
<NavItem to="/tasks/my">My Tasks</NavItem>
<li>
<p className="navbar-text"><code><li></code>s in this nav get the <code>active</code> class</p>
</li>
</ul>
</div>
<div className="col-md-9">
<ActivePara to="/tasks/my" activeClassName="special">
I get highlighted when the My Tasks route is active.
</ActivePara>
{this.props.children}
</div>
</div>
}
})
let TasksDashboard = React.createClass({
render() {
return <div className="TasksDashboard">
<h2>Tasks Dashboard</h2>
</div>
}
})
let AllTasks = React.createClass({
render() {
return <div className="AllTasks">
<h2>All Tasks</h2>
</div>
}
})
let MyTasks = React.createClass({
render() {
return <div className="MyTasks">
<h2>My Tasks</h2>
</div>
}
})
let routes = <Route path="/" component={App}>
<IndexRoute component={Dashboard}/>
<Route path="tasks" component={Tasks}>
<IndexRoute component={TasksDashboard}/>
<Route path="all" component={AllTasks}/>
<Route path="my" component={MyTasks}/>
</Route>
</Route>
render(<Router history={hashHistory} routes={routes}/>, document.querySelector('#demo'))