# Component Lifecycle activate()

**URL:** <https://discourse.aurelia.io/t/component-lifecycle-activate/2346>\
**Category:** Help Requests\
**Created:** [March 6, 2019, 8:42pm UTC](https://discourse.aurelia.io/t/component-lifecycle-activate/2346 "2019-03-06T20:42:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![alternatex](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/alternatex/32/1540_2.png) [@alternatex](https://discourse.aurelia.io/u/alternatex)\
**Post date:** [March 6, 2019, 8:42pm UTC](https://discourse.aurelia.io/t/component-lifecycle-activate/2346/1 "2019-03-06T20:42:11Z")

</div>

I’ve been using this activate() method in my components since I started using Aurelia (I originally came from Durandal) and to this day I have no idea what it does in Aurelia. It’s not even in the [docs](https://aurelia.io/docs/fundamentals/creating-components#the-component-lifecycle) yet it executes right after a component’s constructor. Anyone have any ideas about this? Should I even use it? Why does it work if it’s not in the docs?

---

<div class="post-metadata">

**Author:** ![airboss001](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/airboss001/32/719_2.png) [@airboss001](https://discourse.aurelia.io/u/airboss001)\
**Post date:** [March 6, 2019, 9:02pm UTC](https://discourse.aurelia.io/t/component-lifecycle-activate/2346/2 "2019-03-06T21:02:12Z")

</div>

This might help

> [@The elusive activate() lifecycle method](https://discourse.aurelia.io/t/the-elusive-activate-lifecycle-method/738):
>
> I’m currently using a routing pattern that leverages [routing parameters](http://aurelia.io/docs/routing/configuration#basic-configuration) and the activate() lifecycle method. When reading through the [HTML Behavior Lifecycle](http://aurelia.io/docs/templating/html-behaviors-introduction#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 c…

---

<div class="post-metadata">

**Author:** ![EisenbergEffect](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/eisenbergeffect/32/2655_2.png) [@EisenbergEffect](https://discourse.aurelia.io/u/EisenbergEffect)\
**Post date:** [March 7, 2019, 12:34am UTC](https://discourse.aurelia.io/t/component-lifecycle-activate/2346/3 "2019-03-07T00:34:38Z")

</div>

There are basically _two_ lifecycles in Aurelia. One lifecycle is the component lifecycle. This includes constructor, created, bind, attached, detached and unbind. The second lifecycle is the router lifecycle. It includes canActivate, activate, canDeactivate, and deactivate. However, there’s a special case, which is that anything that is created through the composition engine (via compose element, application root, or manual use of the composition API) will have an activate callback invoked, if present.

We fully acknowledge that the 3rd special case is a bit confusing. We’re working to make this more consistent in vNext.

Let me know if that helps to clarify things and if there are any other questions related to this that we can answer.

---

<div class="post-metadata">

**Author:** ![alternatex](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/alternatex/32/1540_2.png) [@alternatex](https://discourse.aurelia.io/u/alternatex)\
**Post date:** [March 7, 2019, 3:15pm UTC](https://discourse.aurelia.io/t/component-lifecycle-activate/2346/4 "2019-03-07T15:15:02Z")

</div>

Yep that pretty much explains it. Thank you for being such an active member of the community.

---

<div class="post-metadata">

**Author:** ![EisenbergEffect](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/eisenbergeffect/32/2655_2.png) [@EisenbergEffect](https://discourse.aurelia.io/u/EisenbergEffect)\
**Post date:** [March 8, 2019, 12:27am UTC](https://discourse.aurelia.io/t/component-lifecycle-activate/2346/5 "2019-03-08T00:27:17Z")

</div>

You are certainly welcome. I’m looking for more ways to focus on helping people here and improving our documentation. It means trading different responsibilities around on the team to free me up for more of that. So, takes a bit of time, but we’re working on it, so hopefully I’ll be hanging out around here more 🙂

---

<div class="post-metadata">

**Author:** ![jussimattila](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/jussimattila/32/754_2.png) [@jussimattila](https://discourse.aurelia.io/u/jussimattila)\
**Post date:** [March 8, 2019, 12:32pm UTC](https://discourse.aurelia.io/t/component-lifecycle-activate/2346/6 "2019-03-08T12:32:13Z")

</div>

I was directed here after being surprised by `activate()` being called on my root component, but without any arguments. Here’s a conversation I had about this with @bigopon over in Gitter (slightly edited for brevity):

Jussi Mattila @jussimattila 13:59  
I’m building an error page using `aurelia.setRoot("error-page")`. Why is that component not getting any params in `activate()`? `activate()` is called but the arguments are all `undefined`. I have to put a `<router-view>` on the error-page and another component inside that, which will see the params in its `activate(params)`.

bigopon @bigopon 14:17  
it’s because you activated it with composition engine via `setRoot()`

Jussi Mattila @jussimattila 14:18  
ahh, so that is the third special case

bigopon @bigopon 14:18  
yes. the reason it has no parameter in `activate()` is `setRoot()` doesn’t pass a model to composition engine in that 3rd special case, unlike `aurelia-dialog`

Jussi Mattila @jussimattila 14:19  
I actually thought that `setRoot()` is part of routing. or more precisely, component instantiated by `setRoot()` would be part of routing lifecycle

bigopon @bigopon 14:20  
if you look at `<router-view/>`, it’s just some custom element offered by the aurelia team to integrate completely separate worlds: templating + routing

Jussi Mattila @jussimattila 14:21  
right. I have been bit by the missing `<router-view>` every now and then. need to have that to have features “injected” in the component

Hope this makes it even clearer!

---

<div class="post-metadata">

**Author:** ![roddharris](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/roddharris/32/1340_2.png) [@roddharris](https://discourse.aurelia.io/u/roddharris)\
**Post date:** [December 1, 2020, 4:52pm UTC](https://discourse.aurelia.io/t/component-lifecycle-activate/2346/7 "2020-12-01T16:52:50Z")

</div>

Hi Rob,

Thanks for clearing that up – it has been a long-standing point of confusion for me. However, it does beg the question – what kind of code should be placed in `activate` vs ` bind` or `attached` and which should be preferred for things like loading data for the view, etc.?

---

<div class="post-metadata">

**Author:** ![Andy](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/andy/32/1880_2.png) [@Andy](https://discourse.aurelia.io/u/Andy)\
**Post date:** [December 5, 2020, 2:59am UTC](https://discourse.aurelia.io/t/component-lifecycle-activate/2346/8 "2020-12-05T02:59:35Z")

</div>

> [@alternatex](#):
>
> Thank you for being such an active member of the community.

“active member” … uh, he basically invented this whole thing lol
