11import React from 'react' ;
22import ReactDOM from 'react-dom' ;
3- import { HashRouter as Router , Route , Switch } from 'react-router-dom' ;
4- import { withStyles } from " @material-ui/core/styles/index" ;
5- import ExamplesGrid from " ./ExamplesGrid" ;
6- import examples from " ../examples" ;
7- import Button from " @material-ui/core/Button" ;
8- import { withRouter } from 'react-router-dom' ;
3+ import { HashRouter as Router , Route , Switch } from 'react-router-dom' ;
4+ import { withStyles } from ' @material-ui/core/styles/index' ;
5+ import ExamplesGrid from ' ./ExamplesGrid' ;
6+ import examples from ' ../examples' ;
7+ import Button from ' @material-ui/core/Button' ;
8+ import { withRouter } from 'react-router-dom' ;
99
1010const styles = {
11- root : {
12- display : 'flex' ,
13- justifyContent : 'center' ,
14- } ,
15- contentWrapper : {
16- width : '100%' ,
17- } ,
11+ root : {
12+ display : 'flex' ,
13+ justifyContent : 'center' ,
14+ } ,
15+ contentWrapper : {
16+ width : '100%' ,
17+ } ,
1818} ;
1919
2020class Examples extends React . Component {
21+ returnHome = ( ) => {
22+ this . props . history . push ( '/' ) ;
23+ } ;
2124
22- returnHome = ( ) => {
23- this . props . history . push ( '/' ) ;
24- } ;
25-
26- render ( ) {
27- const { classes} = this . props ;
28-
29- var returnHomeStyle = { padding :'0px' , margin :'20px 0 20px 0' } ;
30-
31- return < main className = { classes . root } >
32- < div className = { classes . contentWrapper } >
33- < Switch >
34- < Route path = "/" exact render = { ( ) => < ExamplesGrid examples = { examples } /> } />
35- { Object . keys ( examples ) . map ( ( label , index ) => (
36- < Route key = { index } path = { `/${ label . replace ( / \s + / g, '-' ) . toLowerCase ( ) } ` } exact component = { examples [ label ] } />
37- ) ) }
38- </ Switch >
39- < div >
40- { this . props . location . pathname !== '/' && (
41- < div style = { returnHomeStyle } >
42- < Button color = "primary" onClick = { this . returnHome } > Back to Example Index</ Button >
43- </ div >
44- ) }
45- </ div >
46- </ div >
47- </ main > ;
48- }
25+ render ( ) {
26+ const { classes } = this . props ;
27+
28+ var returnHomeStyle = { padding : '0px' , margin : '20px 0 20px 0' } ;
29+
30+ return (
31+ < main className = { classes . root } >
32+ < div className = { classes . contentWrapper } >
33+ < Switch >
34+ < Route path = "/" exact render = { ( ) => < ExamplesGrid examples = { examples } /> } />
35+ { Object . keys ( examples ) . map ( ( label , index ) => (
36+ < Route
37+ key = { index }
38+ path = { `/${ label . replace ( / \s + / g, '-' ) . toLowerCase ( ) } ` }
39+ exact
40+ component = { examples [ label ] }
41+ />
42+ ) ) }
43+ </ Switch >
44+ < div >
45+ { this . props . location . pathname !== '/' && (
46+ < div style = { returnHomeStyle } >
47+ < Button color = "primary" onClick = { this . returnHome } >
48+ Back to Example Index
49+ </ Button >
50+ </ div >
51+ ) }
52+ </ div >
53+ </ div >
54+ </ main >
55+ ) ;
56+ }
4957}
5058
51- const StyledExamples = withRouter ( withStyles ( styles ) ( Examples ) ) ;
59+ const StyledExamples = withRouter ( withStyles ( styles ) ( Examples ) ) ;
5260
5361function App ( ) {
5462 return (
@@ -58,4 +66,4 @@ function App() {
5866 ) ;
5967}
6068
61- ReactDOM . render ( < App /> , document . getElementById ( 'app-root' ) ) ;
69+ ReactDOM . render ( < App /> , document . getElementById ( 'app-root' ) ) ;
0 commit comments