Skip to content

Commit

Permalink
fix(router): fix reuse strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
mhartington committed May 29, 2018
1 parent 442917d commit bd53bba
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions angular/src/util/ionic-router-reuse-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
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;
}

// tslint:disable-next-line
store(_route: ActivatedRouteSnapshot, _detachedTree: DetachedRouteHandle): void { }
store(_route: ActivatedRouteSnapshot, _detachedTree: DetachedRouteHandle): void {}

shouldAttach(_route: ActivatedRouteSnapshot): boolean {
return false;
Expand All @@ -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;
}
Expand Down

0 comments on commit bd53bba

Please sign in to comment.