UNPKG

2.23 kBJavaScriptView Raw
1import React from 'react';
2import ReactDOM from 'react-dom';
3
4import { AppContainer } from 'react-hot-loader';
5// import walkMD from './walkmd';
6// AppContainer is a necessary wrapper component for HMR
7import {
8 BrowserRouter as Router,
9 Route,
10 Link
11} from 'react-router-dom';
12
13import App from './App';
14
15const Home = () => (
16 <div>
17 <h2>Home</h2>
18 </div>
19)
20
21const About = () => (
22 <div>
23 <h2>About</h2>
24 </div>
25)
26
27const Topic = ({ match }) => (
28 <div>
29 <h3>{match.params.topicId}</h3>
30 </div>
31)
32
33const Topics = ({ match }) => (
34 <div>
35 <h2>Topics</h2>
36 <ul>
37 <li>
38 <Link to={`${match.url}/rendering`}>
39 Rendering with React
40 </Link>
41 </li>
42 <li>
43 <Link to={`${match.url}/components`}>
44 Components
45 </Link>
46 </li>
47 <li>
48 <Link to={`${match.url}/props-v-state`}>
49 Props v. State
50 </Link>
51 </li>
52 </ul>
53
54 <Route path={`${match.url}/:topicId`} component={Topic}/>
55 <Route exact path={match.url} render={() => (
56 <h3>Please select a topic.</h3>
57 )}/>
58 </div>
59)
60
61const BasicExample = () => (
62 <Router>
63 <div>
64 <ul>
65 <li><Link to="/">Home</Link></li>
66 <li><Link to="/about">About</Link></li>
67 <li><Link to="/topics">Topics</Link></li>
68 </ul>
69
70 <hr/>
71 <App />
72 <Route exact path="/" component={Home}/>
73 <Route path="/about" component={About}/>
74 <Route path="/topics" component={Topics}/>
75 </div>
76 </Router>
77)
78
79const render2 = (comp) => {
80 ReactDOM.render(<BasicExample/>, document.getElementById('root'));
81}
82
83const render = (Component) => {
84 ReactDOM.render(
85 <Router>
86 <div>
87 <ul>
88 <li><Link to="/">Home</Link></li>
89 <li><Link to="/about">About</Link></li>
90 <li><Link to="/topics">Topics</Link></li>
91 </ul>
92 <AppContainer>
93 <Component/>
94 </AppContainer>
95 <Route path="/about" component={About}/>
96 <Route path="/topics" component={Topics}/>
97 </div>
98 </Router>
99 ,
100 document.getElementById('root')
101 );
102};
103
104
105
106
107render(App);
108
109
110// Hot Module Replacement API
111if (module.hot) {
112 module.hot.accept('./App', () => {
113 render(App)
114 });
115}
\No newline at end of file