File tree 2 files changed +19
-41
lines changed
2 files changed +19
-41
lines changed Original file line number Diff line number Diff line change 6
6
"prop-types" : " ^15.6.0" ,
7
7
"react" : " ^15.5.4" ,
8
8
"react-dom" : " ^15.5.4"
9
+ "react-router-dom" : " ^4.2.2" ,
9
10
},
10
11
"devDependencies" : {
11
12
"eslint" : " ^3.19.0" ,
Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
+ import {
3
+ BrowserRouter as Router ,
4
+ Route ,
5
+ Link
6
+ } from 'react-router-dom'
2
7
import './App.css'
3
8
import FilterableProductTable from './modules/FilterableProductTable.jsx'
4
9
import ToDoList from './modules/ToDoList.jsx'
5
10
6
11
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
- }
21
12
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
-
42
13
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 >
50
27
)
51
28
}
52
29
}
You can’t perform that action at this time.
0 commit comments