You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
If a route is lazy loaded using a preloading strategy, there is currently no way of knowing when the route is loaded.
Expected behavior
It would be really useful if there was a router Event eg. RouteLazyLoaded that would trigger when a lazy loaded route is preloaded.
Minimal reproduction of the problem with instructions
this.router.events.filter(event=>eventinstanceofRouteLazyLoaded).subscribe(event=>{// perform some action when route is loaded});
What is the motivation / use case for changing the behavior?
The use case is that the angular app can perform some action when the route is loaded.
In my case, I am constructing a multi-level navigation menu that will preload routes as each level is "opened". When the routes are preloaded, the navigation must be updated in order to include the new routes in the list.
@brandonroberts Thanks for the link! Don't know how I missed that! FYI I did open a stack overflow question also, but got no responses. Thanks again and I'll close the issue.
@brandonroberts I've implemented a preloading strategy, however, I'm still unable to tell when a module is actually preloaded. This is my implementation:
import'rxjs/add/observable/of';import{Injectable}from'@angular/core';import{PreloadingStrategy,Route}from'@angular/router';import{Observable}from'rxjs/Observable';
@Injectable()exportclassSelectivePreloadingStrategyimplementsPreloadingStrategy{preloadedModules: Observable<any>[]=[];preload(route: Route,load: ()=>Observable<any>): Observable<any>{if(route.data&&!route.data['preload']){returnObservable.of(null);}else{// log the route path to the consoleconsole.log('[SelectivePreloadingStrategy]: preloading module: '+route.path);returnload().map(res=>{// do something after preloadedconsole.log('module preloaded! res: ',res);return res;});}}}
The first console.log runs correctly for each module that I am preloading. However, the map callback never gets executed.. not sure why this is. Any ideas?
One thing @DzmitryShylovich , I would expect that by the time RouteConfigLoadEnd executes, the route._loadedConfig property would be populated. If not, what is the distinction between RouteConfigLoadStart and RouteConfigLoadEnd ?
Ok, makes sense. It does tell me when the route is loaded (HTTP request is complete).
But it does not tell me when the route has been parsed by angular - ie. route data, route children are not accessible when the RouteConfigLoadEnd event fires.
@conor-mac-aoidh can you please post the final solution to be able to listen when each module is loaded ?!
what i am trying to achieve is to make the custom pre-loading strategy to load each module one after another , since i have more than 30 modules to be loaded upon user login
angular-automatic-lock-bot commented on Sep 14, 2019
Activity
brandonroberts commentedon Jan 20, 2017
There is an example of listening for when routes are preloaded in the guide: https://angular.io/docs/ts/latest/guide/router.html#!#preloading
conor-mac-aoidh commentedon Jan 20, 2017
@brandonroberts Thanks for the link! Don't know how I missed that! FYI I did open a stack overflow question also, but got no responses. Thanks again and I'll close the issue.
conor-mac-aoidh commentedon Jan 23, 2017
@brandonroberts I've implemented a preloading strategy, however, I'm still unable to tell when a module is actually preloaded. This is my implementation:
The first
console.logruns correctly for each module that I am preloading. However, themapcallback never gets executed.. not sure why this is. Any ideas?Thanks again!
Angular version: 2.4.4
johnpapa commentedon Jan 30, 2017
I'd like to see this too, for lazy loaded and preloading events
brandonroberts commentedon Jan 30, 2017
@vicb will you reopen this one?
DzmitryShylovich commentedon Feb 1, 2017
@conor-mac-aoidh Only route available at that point. So event signature would be something
is it ok or do you need something else?
conor-mac-aoidh commentedon Feb 1, 2017
@DzmitryShylovich That would be fine! Thanks
conor-mac-aoidh commentedon Feb 3, 2017
@DzmitryShylovich any idea what version of Angular this feature might appear in?
DzmitryShylovich commentedon Feb 3, 2017
@conor-mac-aoidh it's a feature so in 4.0
conor-mac-aoidh commentedon Feb 3, 2017
@DzmitryShylovich Ok great thanks
conor-mac-aoidh commentedon Feb 28, 2017
Thanks @DzmitryShylovich and @vicb the feature works great in ng4 rc.1 !
conor-mac-aoidh commentedon Feb 28, 2017
One thing @DzmitryShylovich , I would expect that by the time
RouteConfigLoadEndexecutes, theroute._loadedConfigproperty would be populated. If not, what is the distinction betweenRouteConfigLoadStartandRouteConfigLoadEnd?DzmitryShylovich commentedon Feb 28, 2017
https://github.com/angular/angular/blob/master/modules/%40angular/router/src/router_config_loader.ts#L38
conor-mac-aoidh commentedon Feb 28, 2017
Ok, makes sense. It does tell me when the route is loaded (HTTP request is complete).
But it does not tell me when the route has been parsed by angular - ie. route data, route children are not accessible when the
RouteConfigLoadEndevent fires.Could we pass
routesin as a second argument eg:conor-mac-aoidh commentedon Feb 28, 2017
Or, remove
loadChildrenand addchildren:DzmitryShylovich commentedon Mar 3, 2017
@conor-mac-aoidh please file a new issue
feat(router): introduce RouteConfigLoaded event
feat(router): introduce RouteConfigLoaded event
haskalach commentedon Feb 22, 2019
@conor-mac-aoidh can you please post the final solution to be able to listen when each module is loaded ?!
what i am trying to achieve is to make the custom pre-loading strategy to load each module one after another , since i have more than 30 modules to be loaded upon user login
angular-automatic-lock-bot commentedon Sep 14, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.