@@ -36,23 +36,32 @@ var RouterMixin = {
3636 } ,
3737
3838 getInitialState : function ( ) {
39+ return this . getRouterState ( this . props ) ;
40+ } ,
41+
42+ componentWillReceiveProps : function ( nextProps ) {
43+ var nextState = this . getRouterState ( nextProps ) ;
44+ this . replaceState ( nextState ) ;
45+ } ,
46+
47+ getRouterState : function ( props ) {
3948 var path ;
4049 var prefix ;
4150
42- if ( this . props . contextual && this . context . router ) {
51+ if ( props . contextual && this . context . router ) {
4352
4453 var match = this . context . router . getMatch ( ) ;
4554
4655 invariant (
47- this . props . path || isString ( match . unmatchedPath ) ,
56+ props . path || isString ( match . unmatchedPath ) ,
4857 "contextual router has nothing to match on: %s" , match . unmatchedPath
4958 ) ;
5059
51- path = this . props . path || match . unmatchedPath ;
60+ path = props . path || match . unmatchedPath ;
5261 prefix = match . matchedPath ;
5362 } else {
5463
55- path = this . props . path || this . props . environment . getPath ( ) ;
64+ path = props . path || props . environment . getPath ( ) ;
5665
5766 invariant (
5867 isString ( path ) ,
@@ -68,16 +77,12 @@ var RouterMixin = {
6877 }
6978
7079 return {
71- match : matchRoutes ( this . getRoutes ( ) , path ) ,
80+ match : matchRoutes ( this . getRoutes ( props ) , path ) ,
7281 prefix : prefix ,
7382 navigation : { }
7483 } ;
7584 } ,
7685
77- componentWillReceiveProps : function ( ) {
78- this . replaceState ( this . getInitialState ( ) ) ;
79- } ,
80-
8186 /**
8287 * Return parent router or undefined.
8388 */
@@ -126,7 +131,7 @@ var RouterMixin = {
126131 */
127132 setPath : function ( path , navigation , cb ) {
128133 this . replaceState ( {
129- match : matchRoutes ( this . getRoutes ( ) , path ) ,
134+ match : matchRoutes ( this . getRoutes ( this . props ) , path ) ,
130135 prefix : this . state . prefix ,
131136 navigation : navigation
132137 } , cb ) ;
0 commit comments