The elusive activate() lifecycle method

I’m currently using a routing pattern that leverages routing parameters and the activate() lifecycle method. When reading through the HTML Behavior Lifecycle section of the documentation, I noticed that the activate() method isn’t included. This leads me to believe that my architecture is a little off the beaten path.

In my application, I have a large hierarchical list of assets. When clicked, the id for the clicked asset is sent through the route to the HTML Behavior via parameters. The component reads the parameter and fetches the appropriate data from my data store in the activate() method. Am I using an anti-pattern by relying on the activate() method to retrieve my model data? Is there more “Aureliative” way of sending model information to HTML Behaviors?

I’ve noticed that too, but it is included and, I believe, implemented as you are suggesting in the cheat sheet: http://aurelia.io/docs/fundamentals/cheat-sheet#routing

The docs page you refer to is about custom elements, which do not have an activate method. View models that are routes have all lifecycle methods mentioned in that article plus activate, canActivate, canDeactivate and deactivate. Compose elements and dialogs also have an activate.

1 Like

I see. So, I don’t have to worry about my routing approach. This is more about a gap in the Documentation around the ViewModel/Component Lifecycle methods.

Is “ViewModel” or “Component” the correct word to use here? Apparently, I’ve been incorrectly referring to “non-Custom-Elements” as “HTML Behaviors”. I picked this up from the way the Documentation lists the Templating resources.

Using activate in routed view models is fine. In fact, my personal approach is to use canActivateso I can prevent a route completing if data doesn’t load.

Worth acknowledging that custom elements can have an activatemethod, but it only gets called when you’re composing the element using the <compose>and it gets the passed in model parameters. Otherwise, it just gets ignored.

Activate is also called on ViewModels used for the Dialog plugin getting the model data passed in.