Skip to content

Commit

Permalink
fix: lazy loaded route will not load a destroyed module instance, cre…
Browse files Browse the repository at this point in the history
…ates new one instead (angular#24962)
  • Loading branch information
kewde committed Jul 19, 2018
1 parent d76531d commit a78f4b9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/core/src/linker/ng_module_factory.ts
Expand Up @@ -42,6 +42,11 @@ export abstract class NgModuleRef<T> {
*/
abstract destroy(): void;

/**
* Returns whether the module has been destroyed.
*/
abstract get destroyed(): boolean;

/**
* Allows to register a callback that will be called when the module is destroyed.
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/view/refs.ts
Expand Up @@ -520,5 +520,7 @@ class NgModuleRef_ implements NgModuleData, InternalNgModuleRef<any> {
this._destroyListeners.forEach((listener) => listener());
}

get destroyed() { return this._destroyed }

onDestroy(callback: () => void): void { this._destroyListeners.push(callback); }
}
2 changes: 1 addition & 1 deletion packages/router/src/apply_redirects.ts
Expand Up @@ -290,7 +290,7 @@ class ApplyRedirects {

if (route.loadChildren) {
// lazy children belong to the loaded module
if (route._loadedConfig !== undefined) {
if (route._loadedConfig !== undefined && !route._loadedConfig.module.destroyed) {
return of (route._loadedConfig);
}

Expand Down

0 comments on commit a78f4b9

Please sign in to comment.