@@ -123,6 +123,7 @@ export class Router {
123123 private routerEvents : Subject < Event > ;
124124 private navigationId : number = 0 ;
125125 private config : RouterConfig ;
126+ private futureUrlTree : UrlTree ;
126127
127128 /**
128129 * Creates the router service.
@@ -134,6 +135,7 @@ export class Router {
134135 this . resetConfig ( config ) ;
135136 this . routerEvents = new Subject < Event > ( ) ;
136137 this . currentUrlTree = createEmptyUrlTree ( ) ;
138+ this . futureUrlTree = this . currentUrlTree ;
137139 this . currentRouterState = createEmptyState ( this . currentUrlTree , this . rootComponentType ) ;
138140 }
139141
@@ -221,6 +223,18 @@ export class Router {
221223 return createUrlTree ( a , this . currentUrlTree , commands , queryParams , fragment ) ;
222224 }
223225
226+ /**
227+ * Used by RouterLinkWithHref to update HREFs.
228+ * We have to use the futureUrl because we run change detection ind the middle of activation when
229+ * the current url has not been updated yet.
230+ * @internal
231+ */
232+ createUrlTreeUsingFutureUrl (
233+ commands : any [ ] , { relativeTo, queryParams, fragment} : NavigationExtras = { } ) : UrlTree {
234+ const a = relativeTo ? relativeTo : this . routerState . root ;
235+ return createUrlTree ( a , this . futureUrlTree , commands , queryParams , fragment ) ;
236+ }
237+
224238 /**
225239 * Navigate based on the provided url. This navigation is always absolute.
226240 *
@@ -293,20 +307,21 @@ export class Router {
293307 }
294308
295309 return new Promise ( ( resolvePromise , rejectPromise ) => {
296- let updatedUrl : UrlTree ;
297310 let state : RouterState ;
298311 let navigationIsSuccessful : boolean ;
299312 let preActivation : PreActivation ;
300313 applyRedirects ( url , this . config )
301314 . mergeMap ( u => {
302- updatedUrl = u ;
315+ this . futureUrlTree = u ;
303316 return recognize (
304- this . rootComponentType , this . config , updatedUrl , this . serializeUrl ( updatedUrl ) ) ;
317+ this . rootComponentType , this . config , this . futureUrlTree ,
318+ this . serializeUrl ( this . futureUrlTree ) ) ;
305319 } )
306320
307321 . mergeMap ( ( newRouterStateSnapshot ) => {
308322 this . routerEvents . next ( new RoutesRecognized (
309- id , this . serializeUrl ( url ) , this . serializeUrl ( updatedUrl ) , newRouterStateSnapshot ) ) ;
323+ id , this . serializeUrl ( url ) , this . serializeUrl ( this . futureUrlTree ) ,
324+ newRouterStateSnapshot ) ) ;
310325 return resolve ( this . resolver , newRouterStateSnapshot ) ;
311326
312327 } )
@@ -341,10 +356,10 @@ export class Router {
341356
342357 new ActivateRoutes ( state , this . currentRouterState ) . activate ( this . outletMap ) ;
343358
344- this . currentUrlTree = updatedUrl ;
359+ this . currentUrlTree = this . futureUrlTree ;
345360 this . currentRouterState = state ;
346361 if ( ! preventPushState ) {
347- let path = this . urlSerializer . serialize ( updatedUrl ) ;
362+ let path = this . urlSerializer . serialize ( this . futureUrlTree ) ;
348363 if ( this . location . isCurrentPathEqualTo ( path ) ) {
349364 this . location . replaceState ( path ) ;
350365 } else {
@@ -355,8 +370,8 @@ export class Router {
355370 } )
356371 . then (
357372 ( ) => {
358- this . routerEvents . next (
359- new NavigationEnd ( id , this . serializeUrl ( url ) , this . serializeUrl ( updatedUrl ) ) ) ;
373+ this . routerEvents . next ( new NavigationEnd (
374+ id , this . serializeUrl ( url ) , this . serializeUrl ( this . futureUrlTree ) ) ) ;
360375 resolvePromise ( navigationIsSuccessful ) ;
361376 } ,
362377 e => {
0 commit comments