के साथ कस्टम पुन: उपयोग की रणनीति काम नहीं करता है मैं अपने angular2 परियोजना में custom reuse strategy का उपयोग करने की कोशिश की, लेकिन मैंने पाया यह आलसी मॉड्यूल लोड हो रहा है साथ काम नहीं करता। कोई भी जो इस बारे में जानता है? मेरे परियोजना कोणीय 2.6.4Angular2 लेज़ी मॉड्यूल लोड हो रहा है
उपयोग किए जाने वाले strategy.ts
import {RouteReuseStrategy, ActivatedRouteSnapshot, DetachedRouteHandle} from "@angular/router";
export class CustomReuseStrategy implements RouteReuseStrategy {
handlers: {[key: string]: DetachedRouteHandle} = {};
shouldDetach(route: ActivatedRouteSnapshot): boolean {
console.debug('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;
}
}
app.module.ts
const appRoutes: Routes = [
{ path: 'crisis-center', component: CrisisListComponent },
{ path: 'heroes', loadChildren: 'app/hero-list.module#HeroListModule' },
{ path: '', redirectTo: '/crisis-center', pathMatch: 'full' }
];
@NgModule({
imports: [ ... ],
declarations: [ ... ],
providers:[
{provide: RouteReuseStrategy, useClass: CustomReuseStrategy}
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
है और मैं दोनों घटक को <input>
रख दिया और मैं इसे परीक्षण किया गया।
CrisisListComponent
में इनपुट का मूल्य संग्रहीत है, लेकिन HeroListComponent lazy-loaded
का मान संरक्षित नहीं है।
मुझे नहीं पता कि यह अभी तक समर्थित नहीं है। मेरी मदद करने के लिए धन्यवाद।