Search code examples
aurelia

Aurelia routing to the same moduleID


Hi there I have asked this on Gitter, but hope that someone here may be able to help.

I have two different routes that have the same moduleId. I have also set up a setting object within the routes with some data to differentiate what gets rendered. Everything works fine when I navigate to one of these routes from somewhere else, but if I navigate from one to the other neither the constructor or the activate are fired. am i missing something??


Solution

  • I had this problem and it took me a while to find a solution - this should help you I hope;

    You need to add the determineActivationStrategy() method into your class, and then return as below.

    import {activationStrategy} from "aurelia-router";
    
    export class ExampleViewModel {
    
        determineActivationStrategy() {
            return activationStrategy.replace;
        }
    
    }
    

    This will force the VM to be replaced when you're routing to it from itself.

    Here's some more info on the different Activation Strategy types;

    activationStrategy.no-change – reuse instance with no lifecycle events

    activationStrategy.invokeLifecycle – call lifecycle methods on the ViewModel instance each time the route switches

    activationStrategy.replace – construct new instance of ViewModel and invoke full lifecycle on it

    Taken from here ZombieCodeKill - Aurelia Routing Beyond the Basics