I have a custom router-outlet
that caches components.
The code for that is this: https://gist.github.com/waeljammal/467286d64f59f8340a93#file-persistentrouteroutlet-ts-L75
The code example uses the component type as the cache key - however, I need mine to cache by the URL so that I can cache two different instances of the same component.
Is there any way to get the URL based on the ComponentInstruction
?
So I got this working now. The mistake was that I was applying the
PersistenRouterOutlet
to the top level router.Consider the
urlPath: /space/settings/general
.I have a
router-outlet
in my App component, and then I have aWorkspaceComponent
that was bound to thespace
urlPath
.The
WorkspaceComponent
then hosts its ownrouter-outlet
and defines a set of child routes - from the URL, this listens to thesettings/general
part.To solve this, I removed
persistent-router-outlet
from my App component (replaced with the defaultrouter-outlet
.Then in the template for the
WorkspaceComponent
I replaced the defaultrouter-outlet
withpersistent-router-outlet
.Last but not least - the component types that will be instantiated by the child router (inside
WorkspaceComponent
) needs to implement theCanReuse
interface, and implement therouterCanReuse
method:The code for the
PersistentRouterOutlet
is here: