|
1 | 1 | import * as React from "react";
|
2 |
| -import { connect } from "react-redux"; |
| 2 | +import { Switch, Route } from "react-router-dom"; |
3 | 3 |
|
4 |
| -import { Store } from "common/redux/store" |
5 |
| -import { changeTitle } from "common/redux/action" |
6 |
| -import { Title } from "common/component/Title" |
7 |
| -import { Button } from "common/component/Button" |
8 |
| - |
9 |
| -interface AppProps { |
10 |
| - title: string; |
11 |
| - updateTitle: any; |
12 |
| -} |
13 |
| - |
14 |
| -class App extends React.Component<AppProps> { |
15 |
| - titleList: string[] = [ |
16 |
| - "Hello World!", |
17 |
| - "High five from React", |
18 |
| - "Wow. Much skills." |
19 |
| - ]; |
20 |
| - |
21 |
| - constructor(props: AppProps) { |
22 |
| - super(props); |
23 |
| - |
24 |
| - this.setRandomTitle= this.setRandomTitle.bind(this); |
25 |
| - } |
26 |
| - |
27 |
| - public setRandomTitle() { |
28 |
| - let titleIndex = this.titleList.indexOf(this.props.title) + 1; |
29 |
| - if (titleIndex >= this.titleList.length) { |
30 |
| - titleIndex = 0; |
31 |
| - } |
32 |
| - |
33 |
| - const newTitle = this.titleList[titleIndex]; |
34 |
| - this.props.updateTitle(newTitle); |
35 |
| - } |
| 4 | +import Home from "common/container/Home"; |
| 5 | +import Test from "common/container/Test"; |
36 | 6 |
|
| 7 | +export default class App extends React.Component { |
37 | 8 | public render() {
|
38 | 9 | return (
|
39 |
| - <div className="App"> |
40 |
| - <Title> |
41 |
| - {this.props.title} |
42 |
| - </Title> |
43 |
| - <Button onClick={this.setRandomTitle}> |
44 |
| - Update |
45 |
| - </Button> |
46 |
| - </div> |
| 10 | + <main> |
| 11 | + <Switch> |
| 12 | + <Route exact path="/" component={Home} /> |
| 13 | + <Route path="/test" component={Test} /> |
| 14 | + </Switch> |
| 15 | + </main> |
47 | 16 | );
|
48 | 17 | }
|
49 | 18 | }
|
50 |
| - |
51 |
| -const mapStateToProps = (state: Store) => { |
52 |
| - return { |
53 |
| - title: state.title |
54 |
| - } |
55 |
| -} |
56 |
| - |
57 |
| -const mapDispatchToProps = { |
58 |
| - updateTitle: changeTitle |
59 |
| -} |
60 |
| - |
61 |
| -export default connect(mapStateToProps, mapDispatchToProps)(App) |
0 commit comments