Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions angular/src/directives/navigation/ion-router-outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion angular/src/directives/navigation/stack-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class StackController {
}
}

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

Expand Down
3 changes: 2 additions & 1 deletion angular/src/directives/navigation/stack-utils.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -94,5 +94,6 @@ export interface RouteView {
element: HTMLElement;
ref: ComponentRef<any>;
savedData?: any;
savedExtras?: NavigationExtras;
unlistenEvents: () => void;
}
11 changes: 10 additions & 1 deletion angular/src/providers/nav-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}
}
Expand Down