-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChapter13.html
119 lines (108 loc) · 2.21 KB
/
Chapter13.html
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
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Chapter 13 SPA!</title>
<script src="https://unpkg.com/react@15.6.1/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@15.6.1/dist/react-dom.js"></script>
<script src="https://unpkg.com/react-router/umd/react-router.min.js"></script>
<script src="https://unpkg.com/react-router-dom/umd/react-router-dom.min.js"></script>
<style>
body {
background-color: #FFCC00;
padding: 20px;
margin: 0;
}
h1, h2, p, ul, li {
font-family: Helvetica, Arial, sans-serif;
}
header ul li {
display: inline;
list-style-type: none;
margin: 0;
}
header ul {
background-color: #111;
padding: 0;
}
header ul li a {
color: #FFF;
font-weight: bold;
text-decoration: none;
padding: 20px;
display: inline-block;
}
main {
background-color: #FFF;
padding: 20px;
}
main h2 {
padding: 0;
margin: 0;
}
main li {
margin-bottom: 10px;
}
.active {
background-color: #0099FF;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<!-- Your custom script here -->
<script type="text/babel">
// object destructuring in ES6
const {HashRouter, Switch, Route, NavLink} = window.ReactRouterDOM; //"window." is optional here
const Home = () => (
<div>
<h2>Hello</h2>
</div>
);
const Stuff = () => (
<div>
<h2>Stuff</h2>
</div>
);
const Contact = () => (
<div>
<h2>Contact</h2>
</div>
);
const Header = () => (
<header>
<nav>
<ul>
<li><NavLink exact to="/" activeClassName="active">Home</NavLink></li>
<li><NavLink to="/stuff" activeClassName="active">Stuff</NavLink></li>
<li><NavLink to="/contact" activeClassName="active">Contact</NavLink></li>
</ul>
</nav>
</header>
);
const Main = () => (
<main>
<Switch>
<Route exact path='/' component={Home} />
<Route path='/stuff' component={Stuff} />
<Route path='/contact' component={Contact} />
</Switch>
</main>
);
const App = () => (
<div>
<h1>Simple SPA</h1>
<Header/>
<Main />
</div>
);
const destination = document.querySelector("#container");
ReactDOM.render(
<HashRouter>
<App />
</HashRouter>
, destination);
</script>
</body>
</html>