(handle: DetachedRouteHandle)
| 46 | * @see [Manually destroying detached route handles](guide/routing/customizing-route-behavior#manually-destroying-detached-route-handles) |
| 47 | */ |
| 48 | export function destroyDetachedRouteHandle(handle: DetachedRouteHandle): void { |
| 49 | const internalHandle = handle as DetachedRouteHandleInternal; |
| 50 | if (internalHandle && internalHandle.componentRef) { |
| 51 | internalHandle.componentRef.destroy(); |
| 52 | // It is critical to destroy the `_localInjector` here. When a route is detached |
| 53 | // by the `RouteReuseStrategy`, the `_localInjector` is retained because the |
| 54 | // ActivatedRoute object is stored and can be attached later. |
| 55 | // When the developer drops the handle (e.g., deciding not to reuse it), |
| 56 | // they must manually invoke `destroyDetachedRouteHandle` to prevent a memory leak. |
| 57 | internalHandle.route.value._localInjector?.destroy(); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | export interface ExperimentalRouteReuseStrategy { |
| 62 | shouldDestroyInjector?(route: Route): boolean; |
no test coverage detected
searching dependent graphs…