Angular 路由重用策略 - RouteReuseStrategy
import {
RouteReuseStrategy, ActivatedRouteSnapshot, DetachedRouteHandle } from '@angular/router';
interface ICachedRoute {
handle: DetachedRouteHandle;
}
/* istanbul ignore file */
export class CacheRouteReuseStrategy implements RouteReuseStrategy {
private routeCache = new Map<string, ICachedRoute>();
routesToReuse = false;
routeToReuseConfig = [
'/dashboard/YOUR_ROUTE_1',
'/dashboard/YOUR_ROUTE_2',
];
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
return (
future.routeConfig === curr.routeConfig
&& JSON.stringify(future.params) === JSON.stringify(curr.params)
);
}
shouldDetach(route: ActivatedRouteSnapshot): boolean {
/* if config is UI_Constants is false means reuse route will work */
let shouldDetachFlag = false;