mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-16 10:01:59 +08:00
fix(angular): preserve queryParams and fragment when going back (#18298)
fixes #16744
This commit is contained in:
@ -141,6 +141,20 @@ export class IonRouterOutlet implements OnDestroy, OnInit {
|
|||||||
if (this.activated) {
|
if (this.activated) {
|
||||||
if (this.activatedView) {
|
if (this.activatedView) {
|
||||||
this.activatedView.savedData = new Map(this.getContext()!.children['contexts']);
|
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;
|
const c = this.component;
|
||||||
this.activatedView = null;
|
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 { ComponentRef } from '@angular/core';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
|
||||||
import { NavDirection, RouterDirection } from '@ionic/core';
|
import { NavDirection, RouterDirection } from '@ionic/core';
|
||||||
|
|
||||||
export function insertView(views: RouteView[], view: RouteView, direction: RouterDirection) {
|
export function insertView(views: RouteView[], view: RouteView, direction: RouterDirection) {
|
||||||
@ -94,5 +94,6 @@ export interface RouteView {
|
|||||||
element: HTMLElement;
|
element: HTMLElement;
|
||||||
ref: ComponentRef<any>;
|
ref: ComponentRef<any>;
|
||||||
savedData?: any;
|
savedData?: any;
|
||||||
|
savedExtras?: NavigationExtras;
|
||||||
unlistenEvents: () => void;
|
unlistenEvents: () => void;
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,16 @@ export class NavController {
|
|||||||
if (Array.isArray(url)) {
|
if (Array.isArray(url)) {
|
||||||
return this.router!.navigate(url, options);
|
return this.router!.navigate(url, options);
|
||||||
} else {
|
} 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)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user