mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-16 10:01:59 +08:00
feat(router): dont reuse the component if the params are different
This matches v3 functionality
This commit is contained in:
@ -13,5 +13,8 @@ export * from './providers';
|
||||
// ionic types
|
||||
export * from './types/interfaces';
|
||||
|
||||
// ionic oute reuse strategy
|
||||
export * from './util/ionic-router-reuse-strategy';
|
||||
|
||||
/*tslint:disable*/
|
||||
import './ionic-angular';
|
||||
|
28
angular/src/util/ionic-router-reuse-strategy.ts
Normal file
28
angular/src/util/ionic-router-reuse-strategy.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy } from '@angular/router';
|
||||
import { deepEqual, objectValues } from './util';
|
||||
|
||||
export class IonicRouteStrategy implements RouteReuseStrategy {
|
||||
|
||||
shouldDetach(_route: ActivatedRouteSnapshot): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
// tslint:disable-next-line
|
||||
store(_route: ActivatedRouteSnapshot, _detachedTree: DetachedRouteHandle): void { }
|
||||
|
||||
shouldAttach(_route: ActivatedRouteSnapshot): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
retrieve(_route: ActivatedRouteSnapshot): DetachedRouteHandle | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
|
||||
if (objectValues(future.params) && objectValues(curr.params)) {
|
||||
return deepEqual(future.params, curr.params);
|
||||
} else {
|
||||
return future.routeConfig === curr.routeConfig;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,3 +12,24 @@ export function ensureElementInBody(elementName: string) {
|
||||
}
|
||||
return element as HTMLStencilElement;
|
||||
}
|
||||
|
||||
export function objectValues(obj: any): any[] {
|
||||
return Object.keys(obj).map(key => obj[key]);
|
||||
}
|
||||
|
||||
export function deepEqual(x: any, y: any) {
|
||||
if (x === y) {
|
||||
return true;
|
||||
} else if (typeof x === 'object' && x != null && (typeof y === 'object' && y != null)) {
|
||||
if (Object.keys(x).length !== Object.keys(y).length) return false;
|
||||
|
||||
for (const prop in x) {
|
||||
if (y.hasOwnProperty(prop)) {
|
||||
if (!deepEqual(x[prop], y[prop])) return false;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user