mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 05:58:26 +08:00
fix(router): fix reuse strategy
This commit is contained in:
@ -1,8 +1,11 @@
|
||||
import { ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy } from '@angular/router';
|
||||
import {
|
||||
ActivatedRouteSnapshot,
|
||||
DetachedRouteHandle,
|
||||
RouteReuseStrategy
|
||||
} from '@angular/router';
|
||||
import { deepEqual, objectValues } from './util';
|
||||
|
||||
export class IonicRouteStrategy implements RouteReuseStrategy {
|
||||
|
||||
shouldDetach(_route: ActivatedRouteSnapshot): boolean {
|
||||
return false;
|
||||
}
|
||||
@ -18,14 +21,25 @@ export class IonicRouteStrategy implements RouteReuseStrategy {
|
||||
return null;
|
||||
}
|
||||
|
||||
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
|
||||
shouldReuseRoute(
|
||||
future: ActivatedRouteSnapshot,
|
||||
curr: ActivatedRouteSnapshot
|
||||
): boolean {
|
||||
// checking router params
|
||||
const futureParams = objectValues(future.params);
|
||||
const currParams = objectValues(curr.params);
|
||||
|
||||
if (futureParams && !!futureParams.length && currParams && currParams.length > 0) {
|
||||
if (
|
||||
futureParams &&
|
||||
!!futureParams.length &&
|
||||
currParams &&
|
||||
currParams.length > 0
|
||||
) {
|
||||
// If the router params do not match, render the new component
|
||||
return deepEqual(future.params, curr.params);
|
||||
return (
|
||||
deepEqual(future.params, curr.params) &&
|
||||
future.routeConfig === curr.routeConfig
|
||||
);
|
||||
} else {
|
||||
return future.routeConfig === curr.routeConfig;
|
||||
}
|
||||
|
Reference in New Issue
Block a user