Activate() not called when previous route uses same module?!

Hey Aurelians

I’ve been using activate() for all sorts of things on route view models for quite some time and it has worked just fine so far. But now, I’m really puzzled and do hope someone can shed some light on this:

I’ve got two simple routes configured

config.map([
      {
        route: 'one',
        name: 'route1',
        moduleId: PLATFORM.moduleName('apps/website/routes/standard'),
        nav: true,
        title: 'One',
        settings: {content: this.pages[0]}
      },
      {
        route: 'two',
        name: 'route2',
        moduleId: PLATFORM.moduleName('apps/website/routes/standard'),
        nav: true,
        title: 'Two',
        settings: {content: this.pages[0]}
      }
    ]);

So this just be straight forward. Both routes show up just fine in the navigation. But somehow activate() (or canActivate() as well) is not being called when I switch from one route to the other. Only when the two routes use different modules, the methods are called. Is this intended behaviour that I just have not encountered so far or am I doing something wrong?

I’m happy to provide more info if needed.

Thanks!
Will

since its the same viewmodel by default it gets reused so no lifecycle hooks are called. you can override the behavior as mentioned here Router Configuration | Aurelia

1 Like

Hm… I’ve spent so much time on that particular documentation page over the last few years, but somehow I must have missed this section so far! Thanks so much for pointing it out @zewa666 !

Same here. I’ve recently implemented a view where I use the query parameters for subsequent changes to the view, and nothing was changing. This solved my problem for me.

glad it helped. i just remember it because I’ve written that part :sweat_smile:

1 Like

While looking for a solution to dynamic routes in nested routers, I accidentally tripped of this post:

Apparently activationStrategy.invokeLifecycle; does the trick, no need to set it to replace.

1 Like