• Overview
@angular/router

withExperimentalAutoCleanupInjectors

function

Enables automatic destruction of unused route injectors.

API

function withExperimentalAutoCleanupInjectors(): ExperimentalAutoCleanupInjectorsFeature;

Description

When enabled, the router will automatically destroy EnvironmentInjectors associated with Routes that are no longer active or stored by the RouteReuseStrategy.

This feature is opt-in and requires RouteReuseStrategy.shouldDestroyInjector to return true for the routes that should be destroyed. If the RouteReuseStrategy uses stored handles, it should also implement retrieveStoredHandle to ensure we don't destroy injectors for handles that will be reattached.

Jump to details