Skip to content
Permalink
Browse files

fix(angular): preserve queryParams and fragment when going back (#18298)

fixes #16744
  • Loading branch information...
liamdebeasi committed May 20, 2019
1 parent da38647 commit bdd5109dbeef25fd68ef2b9eff0a40f82ec21a8b
@@ -141,6 +141,20 @@ export class IonRouterOutlet implements OnDestroy, OnInit {
if (this.activated) {
if (this.activatedView) {
this.activatedView.savedData = new Map(this.getContext()!.children['contexts']);

/**
* Ensure we are saving the NavigationExtras
* data otherwise it will be lost
*/
this.activatedView.savedExtras = {};
const context = this.getContext()!;

if (context.route) {
const contextSnapshot = context.route.snapshot;

this.activatedView.savedExtras.queryParams = contextSnapshot.queryParams;
this.activatedView.savedExtras.fragment = contextSnapshot.fragment;
}
}
const c = this.component;
this.activatedView = null;
@@ -132,7 +132,7 @@ export class StackController {
}
}

return this.navCtrl.navigateBack(url).then(() => true);
return this.navCtrl.navigateBack(url, view.savedExtras).then(() => true);
});
}

@@ -1,5 +1,5 @@
import { ComponentRef } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
import { NavDirection, RouterDirection } from '@ionic/core';

export function insertView(views: RouteView[], view: RouteView, direction: RouterDirection) {
@@ -94,5 +94,6 @@ export interface RouteView {
element: HTMLElement;
ref: ComponentRef<any>;
savedData?: any;
savedExtras?: NavigationExtras;
unlistenEvents: () => void;
}
@@ -184,7 +184,16 @@ export class NavController {
if (Array.isArray(url)) {
return this.router!.navigate(url, options);
} else {
return this.router!.navigateByUrl(url, options);

/**
* navigateByUrl ignores any properties that
* would change the url, so things like queryParams
* would be ignored unless we create a url tree
* More Info: https://github.com/angular/angular/issues/18798
*/
return this.router!.navigateByUrl(
this.router!.createUrlTree([url], options)
);
}
}
}

0 comments on commit bdd5109

Please sign in to comment.
You can’t perform that action at this time.