Angular2 doesn't work Custom Reuse Strategy with Lazy module loading

前端 未结 5 1166
花落未央
花落未央 2020-12-08 16:52

I tried to use custom reuse strategy in my angular2 project, but I found it doesn\'t work with lazy module loading. Anyone who know about this? My project i

5条回答
  •  悲&欢浪女
    2020-12-08 17:13

    To make it work you should take into account the full path instead of simple route.routeConfig.path as most articles suggests. For example:

    private getKey(route: ActivatedRouteSnapshot): string {
        return route.pathFromRoot
            .map((el: ActivatedRouteSnapshot) => el.routeConfig ? el.routeConfig.path : '')
            .filter(str => str.length > 0)
            .join('');
    }
    
    store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle): void {
        this.handlers[this.getKey(route)] = handle;
    }
    

提交回复
热议问题