File tree 4 files changed +68
-11
lines changed
4 files changed +68
-11
lines changed Original file line number Diff line number Diff line change @@ -3,26 +3,34 @@ import ReactDOM from 'react-dom';
3
3
import Modal from 'react-modal' ;
4
4
import SimpleUsage from './simple_usage' ;
5
5
import MultipleModals from './multiple_modals' ;
6
+ import ReactRouter from './react-router' ;
6
7
7
8
const appElement = document . getElementById ( 'example' ) ;
8
9
9
10
Modal . setAppElement ( '#example' ) ;
10
11
11
12
const examples = [
12
13
SimpleUsage ,
13
- MultipleModals
14
+ MultipleModals ,
15
+ ReactRouter
14
16
] ;
15
17
16
- function App ( props ) {
17
- return examples . map ( ( example , key ) => {
18
- const ExampleApp = example . app ;
18
+ class App extends Component {
19
+ render ( ) {
19
20
return (
20
- < div key = { key } className = "example" >
21
- < h3 > { example . label } </ h3 >
22
- < ExampleApp />
21
+ < div >
22
+ { examples . map ( ( example , key ) => {
23
+ const ExampleApp = example . app ;
24
+ return (
25
+ < div key = { key } className = "example" >
26
+ < h3 > { example . label } </ h3 >
27
+ < ExampleApp />
28
+ </ div >
29
+ ) ;
30
+ } ) }
23
31
</ div >
24
32
) ;
25
- } ) ;
33
+ }
26
34
}
27
35
28
- ReactDOM . render ( < App /> , appElement ) ;
36
+ ReactDOM . render ( < App /> , appElement ) ;
Original file line number Diff line number Diff line change
1
+ import PropTypes from 'prop-types' ;
2
+ import React , { Component } from 'react' ;
3
+ import createHistory from 'history/createBrowserHistory' ;
4
+ import { Router , Route , Switch } from 'react-router' ;
5
+ import { Link } from 'react-router-dom' ;
6
+ import Modal from 'react-modal' ;
7
+
8
+ const history = createHistory ( ) ;
9
+
10
+ const Content = label => ( ) => < p > { `Content ${ label } ` } </ p > ;
11
+
12
+ const shouldOpenModal = locationPath => / \b m o d a l \b / . test ( locationPath ) ;
13
+
14
+ const ReactRouterModal = props => (
15
+ < Modal
16
+ isOpen = { shouldOpenModal ( props . location . pathname ) }
17
+ onRequestClose = { ( ) => history . push ( "/basic" ) } >
18
+ < div >
19
+ < Link to = "/basic/modal/a" > Link A</ Link > < br />
20
+ < Link to = "/basic/modal/b" > Link B</ Link >
21
+ < div >
22
+ < Switch location = { props . location } >
23
+ < Route path = "/basic/modal/a" component = { Content ( 'A' ) } />
24
+ < Route path = "/basic/modal/b" component = { Content ( 'B' ) } />
25
+ </ Switch >
26
+ </ div >
27
+ </ div >
28
+ </ Modal >
29
+ ) ;
30
+
31
+ class App extends Component {
32
+ render ( ) {
33
+ return (
34
+ < Router history = { history } >
35
+ < div >
36
+ < Link to = "/basic/modal" className = "btn btn-primary" > Modal</ Link >
37
+ < Route path = "/basic/modal" component = { ReactRouterModal } />
38
+ </ div >
39
+ </ Router >
40
+ ) ;
41
+ }
42
+ }
43
+
44
+ export default {
45
+ label : "#3. react-modal and react-router." ,
46
+ app : App
47
+ } ;
Original file line number Diff line number Diff line change 48
48
"npm-run-all" : " ^4.1.1" ,
49
49
"react" : " ^15.6.1" ,
50
50
"react-dom" : " ^15.6.1" ,
51
+ "react-router" : " ^4.2.0" ,
52
+ "react-router-dom" : " ^4.2.2" ,
51
53
"should" : " ^13.1.0" ,
52
54
"sinon" : " next" ,
53
55
"uglify-js" : " 3.1.1" ,
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ module.exports = {
29
29
output : {
30
30
filename : '[name].js' ,
31
31
chunkFilename : '[id].chunk.js' ,
32
- path : ' examples/__build__',
32
+ path : path . resolve ( __dirname , './ examples/__build__') ,
33
33
publicPath : '/__build__/'
34
34
} ,
35
35
@@ -46,7 +46,7 @@ module.exports = {
46
46
} ,
47
47
48
48
plugins : [
49
- new webpack . optimize . CommonsChunkPlugin ( 'shared.js ' ) ,
49
+ new webpack . optimize . CommonsChunkPlugin ( 'shared' ) ,
50
50
new webpack . LoaderOptionsPlugin ( { debug : true } )
51
51
]
52
52
You can’t perform that action at this time.
0 commit comments