1
1
import React from 'react' ;
2
+ import createHistory from 'history/lib/createHashHistory' ;
2
3
import { Router , Link } from 'react-router' ;
3
- import HashHistory from 'react-router/lib/HashHistory' ;
4
- var history = new HashHistory ( { queryKey : 'k' } ) ;
4
+
5
+ var history = createHistory ( ) ;
5
6
6
7
var pictures = [
7
- { id : 0 , src : 'http://placekitten.com/601/601' } ,
8
- { id : 1 , src : 'http://placekitten.com/610/610' } ,
9
- { id : 2 , src : 'http://placekitten.com/620/620' } ,
8
+ { id : 0 , src : 'http://placekitten.com/601/601' } ,
9
+ { id : 1 , src : 'http://placekitten.com/610/610' } ,
10
+ { id : 2 , src : 'http://placekitten.com/620/620' }
10
11
] ;
11
12
12
13
var App = React . createClass ( {
13
- render ( ) {
14
+ render ( ) {
14
15
return (
15
16
< div >
16
17
< h1 > Pinterest Style Routes</ h1 >
@@ -33,7 +34,6 @@ var App = React.createClass({
33
34
} ) ;
34
35
35
36
var Feed = React . createClass ( {
36
-
37
37
overlayStyles : {
38
38
position : 'fixed' ,
39
39
top : 30 ,
@@ -46,16 +46,13 @@ var Feed = React.createClass({
46
46
background : '#fff'
47
47
} ,
48
48
49
- render ( ) {
49
+ render ( ) {
50
50
return (
51
51
< div >
52
52
< div >
53
53
{ pictures . map ( picture => (
54
- < Link
55
- to = { `/pictures/${ picture . id } ` }
56
- state = { { fromFeed : true } }
57
- >
58
- < img style = { { margin : 10 } } src = { picture . src } height = "100" />
54
+ < Link key = { picture . id } to = { `/pictures/${ picture . id } ` } state = { { fromFeed : true } } >
55
+ < img style = { { margin : 10 } } src = { picture . src } height = "100" />
59
56
</ Link >
60
57
) ) }
61
58
</ div >
@@ -70,7 +67,7 @@ var Feed = React.createClass({
70
67
} ) ;
71
68
72
69
var FeedPicture = React . createClass ( {
73
- render ( ) {
70
+ render ( ) {
74
71
return (
75
72
< div >
76
73
< h2 > Inside the feed</ h2 >
@@ -84,7 +81,7 @@ var FeedPicture = React.createClass({
84
81
} ) ;
85
82
86
83
var Picture = React . createClass ( {
87
- render ( ) {
84
+ render ( ) {
88
85
return (
89
86
< div >
90
87
< h2 > Not Inside the feed</ h2 >
@@ -104,7 +101,7 @@ var FeedPictureRoute = {
104
101
105
102
var FeedRoute = {
106
103
component : Feed ,
107
- childRoutes : [ FeedPictureRoute ] ,
104
+ childRoutes : [ FeedPictureRoute ]
108
105
} ;
109
106
110
107
var PictureRoute = {
@@ -117,18 +114,19 @@ var RootRoute = {
117
114
component : App ,
118
115
indexRoute : FeedRoute ,
119
116
120
- getChildRoutes ( state , cb ) {
117
+ getChildRoutes ( location , cb ) {
118
+ var { state } = location ;
119
+
121
120
if ( state && state . fromFeed ) {
122
121
cb ( null , [ FeedRoute ] ) ;
123
- }
124
- else {
122
+ } else {
125
123
cb ( null , [ PictureRoute ] ) ;
126
124
}
127
125
}
128
126
} ;
129
127
130
128
React . render (
131
- < Router history = { history } children = { RootRoute } /> ,
129
+ < Router history = { history } children = { RootRoute } /> ,
132
130
document . getElementById ( 'example' )
133
131
) ;
134
132
0 commit comments