简体   繁体   中英

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??

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

这里找到了答案:)虽然不是一个完整的解决方案开箱即用,但实现是可能的

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM