-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
57 lines (49 loc) · 1.58 KB
/
client.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
var React = require("react");
var ReactDOM = require("react-dom");
import {Router, Route, hashHistory, IndexRoute} from "react-router";
var data = require("./data/2010.json");
// data = JSON.parse(data);
// React components
var Home = require("./components/home-component.js");
var Teams = require("./components/teams-component.js");
var Matches = require("./components/matches-component.js");
var Rankings = require("./components/rankings-component.js");
var Navigation = require("./components/navigation-component.js");
var App = React.createClass({
getInitialState:function(){
return {
data: data
};
}, // getInitialState
render: function(){
var componentState = this.state;
// Updating the children components, to have the state by default.
var children = React.Children.map(this.props.children, function(child, index){
return React.cloneElement(child, componentState) ;
}.bind(this));
return(
<div>
<h1>2010 World cup, from React's perspective</h1>
<Navigation activeItem={this.props.location.pathname}/>
{children}
</div>
);
}
});
var routes = (
<Router history={hashHistory}>
<Route path="/" component={App} >
<IndexRoute component={Home} />
<Route path="teams" component={Teams} />
<Route path="matches" component={Matches} />
{/* matches/* will accept any round passed into it */}
{/* example: #/matches/first-round */}
<Route path="matches/*" component={Matches} />
<Route path="rankings" component={Rankings} />
</Route>
</Router>
);
ReactDOM.render(
routes ,
document.getElementById("react-container")
);