Angular2 doesn't work Custom Reuse Strategy with Lazy module loading

前端 未结 5 1152
花落未央
花落未央 2020-12-08 16:52

I tried to use custom reuse strategy in my angular2 project, but I found it doesn\'t work with lazy module loading. Anyone who know about this? My project i

5条回答
  •  既然无缘
    2020-12-08 17:26

    RouteReuseStrategy does work with LazyLoaded components.

    The problem here is that you're using route.routeConfig.path as the key to store and retrieve the Handles.

    I don't know why, but with LazyLoaded modules, route.routeConfig.path is empty when executing shouldAttach

    The solution I use is to define a custom key in my routes, like:

    { path: '...', loadChildren: '...module#...Module', data: { key: 'custom_key' } }
    

    This key value can be easily accessed in the ActivatedRouteSnapshot, like:

    route.data.key
    

    With this key you can store and retrieve the handles correctly.

提交回复
热议问题