@@ -2,7 +2,7 @@ import React from 'react';
22import PropTypes from 'prop-types' ;
33import BaseRouterComponent from './Base' ;
44import { ID_DELIM , __DEV__ } from '../constants' ;
5- import { push as actionPush } from '../actions' ;
5+ import { replace } from '../actions' ;
66
77class Fragment extends BaseRouterComponent {
88
@@ -41,24 +41,28 @@ class Fragment extends BaseRouterComponent {
4141
4242 if ( ! this . isSubscribed ) return ;
4343
44- const routerStore = this . getStatefromStore ( ) ;
4544 const { immutable, parseRoute } = this . router ;
46- const { redirect, push } = newProps || this . props ;
45+ const { redirect } = newProps || this . props ;
46+
4747 const current = this . current ;
48+ const storeState = this . getStatefromStore ( ) ;
49+ const routerStore = immutable ? storeState . toJS ( ) : storeState ;
4850
4951 if ( routerStore ) {
50- const idPath = immutable ? routerStore . getIn ( [ 'route' , 'idPath' ] ) : routerStore . route . idPath ;
52+ const idPath = routerStore . route . idPath ;
53+ const params = routerStore . route . params ;
54+ const query = routerStore . query ;
55+ const hash = routerStore . hash ;
5156 const routePath = idPath + ID_DELIM ;
5257 const fragmentPath = current + ID_DELIM ;
5358 const match = ( routePath ) . indexOf ( fragmentPath ) ;
5459 const matchExact = routePath === fragmentPath ;
5560
5661 if ( matchExact && redirect ) {
57- return this . store . dispatch ( push (
58- typeof redirect === 'object' && redirect . id
59- ? parseRoute ( redirect )
60- : redirect
61- ) ) ;
62+ const redirectRoute = typeof redirect === 'object' && redirect . id ?
63+ parseRoute ( { ...{ params, query, hash } , ...redirect } ) : redirect ;
64+
65+ return this . store . dispatch ( replace ( redirectRoute ) ) ;
6266 }
6367
6468 if ( match === 0 && ! this . state . visible ) {
@@ -101,10 +105,6 @@ Fragment.childContextTypes = {
101105 store : PropTypes . object
102106} ;
103107
104- Fragment . defaultProps = {
105- push : actionPush
106- } ;
107-
108108if ( __DEV__ ) {
109109 Fragment . propTypes = {
110110 id : PropTypes . oneOfType ( [
@@ -120,8 +120,7 @@ if (__DEV__) {
120120 redirect : PropTypes . oneOfType ( [
121121 PropTypes . object ,
122122 PropTypes . string
123- ] ) ,
124- push : PropTypes . func . isRequired
123+ ] )
125124 } ;
126125}
127126
0 commit comments