Skip to content

Commit 662ba18

Browse files
committed
add react-router-dom
1 parent 2d18a16 commit 662ba18

File tree

2 files changed

+19
-41
lines changed

2 files changed

+19
-41
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"prop-types": "^15.6.0",
77
"react": "^15.5.4",
88
"react-dom": "^15.5.4"
9+
"react-router-dom": "^4.2.2",
910
},
1011
"devDependencies": {
1112
"eslint": "^3.19.0",

src/App.jsx

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,29 @@
11
import React from 'react'
2+
import {
3+
BrowserRouter as Router,
4+
Route,
5+
Link
6+
} from 'react-router-dom'
27
import './App.css'
38
import FilterableProductTable from './modules/FilterableProductTable.jsx'
49
import ToDoList from './modules/ToDoList.jsx'
510

611
class App extends React.Component {
7-
state = {
8-
currentComponent: 'FilterableProductTable'
9-
}
10-
11-
components = {
12-
FilterableProductTable: FilterableProductTable,
13-
ToDoList: ToDoList
14-
}
15-
16-
handleDemoClick(componentName) {
17-
this.setState({
18-
currentComponent: componentName
19-
})
20-
}
2112
render() {
22-
let lis = [],
23-
CurrentComponent
24-
25-
CurrentComponent = this.components[this.state.currentComponent]
26-
27-
Object.keys(this.components).forEach((componentName) => {
28-
let name
29-
30-
name = this.state.currentComponent === componentName ?
31-
(<span style={{color:'green'}}>
32-
{componentName}
33-
</span>) : componentName
34-
35-
lis.push(
36-
<li
37-
onClick={this.handleDemoClick.bind(this, componentName)}
38-
key={componentName}>{name}</li>
39-
)
40-
})
41-
4213
return (
43-
<div id="app">
44-
<h1>Demos</h1>
45-
<ul>
46-
{lis}
47-
</ul>
48-
<CurrentComponent />
49-
</div>
14+
<Router>
15+
<div>
16+
<ul>
17+
<li><Link to="/">FilterableProductTable</Link></li>
18+
<li><Link to="/todos">ToDoList</Link></li>
19+
</ul>
20+
21+
<hr/>
22+
23+
<Route exact path="/" component={FilterableProductTable}/>
24+
<Route path="/todos" component={ToDoList}/>
25+
</div>
26+
</Router>
5027
)
5128
}
5229
}

0 commit comments

Comments
 (0)