@@ -5,12 +5,8 @@ var canUseDOM = require('react/lib/ExecutionEnvironment').canUseDOM;
5
5
var Promise = require ( 'when/lib/Promise' ) ;
6
6
var LocationActions = require ( '../actions/LocationActions' ) ;
7
7
var Route = require ( '../components/Route' ) ;
8
- var DefaultLocation = require ( '../locations/DefaultLocation' ) ;
9
- var HashLocation = require ( '../locations/HashLocation' ) ;
10
- var HistoryLocation = require ( '../locations/HistoryLocation' ) ;
11
- var RefreshLocation = require ( '../locations/RefreshLocation' ) ;
12
8
var ActiveDelegate = require ( '../mixins/ActiveDelegate' ) ;
13
- var PathStore = require ( '../stores/PathStore ' ) ;
9
+ var PathListener = require ( '../mixins/PathListener ' ) ;
14
10
var RouteStore = require ( '../stores/RouteStore' ) ;
15
11
var Path = require ( '../utils/Path' ) ;
16
12
var Redirect = require ( '../utils/Redirect' ) ;
@@ -21,15 +17,6 @@ var Transition = require('../utils/Transition');
21
17
*/
22
18
var REF_NAME = '__activeRoute__' ;
23
19
24
- /**
25
- * A hash of { name, location } pairs of all locations.
26
- */
27
- var NAMED_LOCATIONS = {
28
- hash : HashLocation ,
29
- history : HistoryLocation ,
30
- refresh : RefreshLocation
31
- } ;
32
-
33
20
/**
34
21
* The default handler for aborted transitions. Redirects replace
35
22
* the current URL and all others roll it back.
@@ -81,26 +68,19 @@ var Routes = React.createClass({
81
68
82
69
displayName : 'Routes' ,
83
70
84
- mixins : [ ActiveDelegate ] ,
71
+ mixins : [ ActiveDelegate , PathListener ] ,
85
72
86
73
propTypes : {
87
74
onAbortedTransition : React . PropTypes . func . isRequired ,
88
75
onTransitionError : React . PropTypes . func . isRequired ,
89
- preserveScrollPosition : React . PropTypes . bool ,
90
- location : function ( props , propName , componentName ) {
91
- var location = props [ propName ] ;
92
-
93
- if ( typeof location === 'string' && ! ( location in NAMED_LOCATIONS ) )
94
- return new Error ( 'Unknown location "' + location + '", see ' + componentName ) ;
95
- }
76
+ preserveScrollPosition : React . PropTypes . bool
96
77
} ,
97
78
98
79
getDefaultProps : function ( ) {
99
80
return {
100
81
onAbortedTransition : defaultAbortedTransitionHandler ,
101
82
onTransitionError : defaultTransitionErrorHandler ,
102
- preserveScrollPosition : false ,
103
- location : DefaultLocation
83
+ preserveScrollPosition : false
104
84
} ;
105
85
} ,
106
86
@@ -110,35 +90,6 @@ var Routes = React.createClass({
110
90
} ;
111
91
} ,
112
92
113
- componentWillMount : function ( ) {
114
- PathStore . setup ( this . getLocation ( ) ) ;
115
- } ,
116
-
117
- componentDidMount : function ( ) {
118
- PathStore . addChangeListener ( this . handlePathChange ) ;
119
- this . handlePathChange ( ) ;
120
- } ,
121
-
122
- componentWillUnmount : function ( ) {
123
- PathStore . removeChangeListener ( this . handlePathChange ) ;
124
- } ,
125
-
126
- handlePathChange : function ( ) {
127
- this . transitionTo ( PathStore . getCurrentPath ( ) ) ;
128
- } ,
129
-
130
- /**
131
- * Gets the location object this component uses to watch for URL changes.
132
- */
133
- getLocation : function ( ) {
134
- var location = this . props . location ;
135
-
136
- if ( typeof location === 'string' )
137
- return NAMED_LOCATIONS [ location ] ;
138
-
139
- return location ;
140
- } ,
141
-
142
93
/**
143
94
* Gets the <Route> component that is currently active.
144
95
*/
@@ -188,7 +139,7 @@ var Routes = React.createClass({
188
139
* If you want to keep the URL in sync with transitions, use Router.transitionTo,
189
140
* Router.replaceWith, or Router.goBack instead.
190
141
*/
191
- transitionTo : function ( path ) {
142
+ updatePath : function ( path ) {
192
143
var routes = this ;
193
144
var transition = new Transition ( path ) ;
194
145
0 commit comments