forked from reactjs/react-router-tutorial
/
App.jsx
54 lines (47 loc) · 1.52 KB
/
App.jsx
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
import React from 'react';
import htmlescape from 'htmlescape';
import { Route } from 'react-router-dom';
import NavLink from './NavLink';
import Home from './Home';
import Repos from './Repos';
import About from './About';
export default class extends React.Component {
constructor(props, context) {
super(props, context);
this.state = { title: 0 };
}
componentWillMount() {
if (this.props.initialProps) console.log('The props are here woop', this.props.initialProps);
}
componentDidMount() {
setInterval(
() => { this.setState({ title: Math.round(Math.random() * 100) / 100 }); },
1000,
);
}
render() {
return (
<html lang="en">
<head>
<title>{`${this.state.title} (no react-helmet needed)`}</title>
</head>
<body>
<h1>React Router Tutorial</h1>
<ul>
<li><NavLink to="/" exact>Home</NavLink></li>
<li><NavLink to="/about">About</NavLink></li>
<li><NavLink to="/repos">Repos</NavLink></li>
</ul>
<Route exact path="/" component={Home} />
<Route exact path="/about" component={About} />
<Route path="/repos" component={Repos} />
{/* for mounting React with the server side props in the client */}
<script
dangerouslySetInnerHTML={{ __html: `window.reactData=${htmlescape(this.props.initialProps)}` }} // eslint-disable-line react/no-danger
/>
<script src="/bundle.js" />
</body>
</html>
);
}
}