Detached() not firing in composed view

My problem is this:

I have a view (with its own viewmodel) that has 2 composed view/viewmodel pairs inside it. One of these ‘embedded’ viewmodels has an Aurelia eventAggregator subscriber defined in activate(). I want to dispose() of this subscriber in the ‘embedded’ VM’s detached() method. However, the ‘embedded’ detached() method never seems to run, when navigating away from the (outer or ‘main’) view, although the outer or ‘main’ view’s detached() method DOES fire

One result of this is that the subscribed event in the ‘embedded’ viewmodel continues to receive events, even though the page within which it is contained has been navigated away from. Obviously totally undesirable!

Any ideas please?

Cheers

1 Like

From the source code, https://github.com/aurelia/templating-resources/blob/master/src/compose.js, it does not seem <compose/> handles attached/detached life cycle. You can use bind, unbind to work around it. Unfortunately we cannot add it in at this stage as it could be a big breaking change. Note that detached will still fire in the end. Im interested in your scenario, can you share a simple gist to demonstrate the issue ?

dunno if I remember wrong/mixing this with something else. Have you tried router typical events.

  • activate
  • deactivate

There is an issue for that,
it’s syays there that deactivate is never called.