如何使用延迟加载模块实现Angular2 RouterUseStrategy?

如何使用延迟加载模块实现Angular2 RouterUseStrategy?,angular,lazy-loading,Angular,Lazy Loading,尝试使用 export class CustomReuseStrategy implements RouteReuseStrategy {} 但无法从根目录获取延迟加载模块的url。请帮助创建缓存处理程序。这里是我的自定义重用策略: import {RouteReuseStrategy, DetachedRouteHandle, ActivatedRouteSnapshot} from '@angular/router'; export class CustomReuseStrategy

尝试使用

export class CustomReuseStrategy implements RouteReuseStrategy {}
但无法从根目录获取延迟加载模块的url。请帮助创建缓存处理程序。这里是我的自定义重用策略:

import {RouteReuseStrategy, DetachedRouteHandle, ActivatedRouteSnapshot} from '@angular/router';


export class CustomReuseStrategy implements RouteReuseStrategy {

    handlers: {[key: string]: DetachedRouteHandle} = {};

    shouldDetach(route: ActivatedRouteSnapshot): boolean {
        console.info('CustomReuseStrategy:shouldDetach', route);
        return true;
    }

    store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle): void {
        console.debug('CustomReuseStrategy:store', route, handle);
        this.handlers[route.routeConfig.path] = handle;
    }

    shouldAttach(route: ActivatedRouteSnapshot): boolean {
        console.debug('CustomReuseStrategy:shouldAttach', route);
        return !!route.routeConfig && !!this.handlers[route.routeConfig.path];
    }

    retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle {
        console.debug('CustomReuseStrategy:retrieve', route);
        if (!route.routeConfig) return null;
        return this.handlers[route.routeConfig.path];
    }

    shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
        console.debug('CustomReuseStrategy:shouldReuseRoute', future, curr);
        return future.routeConfig === curr.routeConfig;
    }
}

谢谢你的回答。

是这样做的-看起来很有效。如果有更好的办法,请告诉我。