shell.js中的Durandal viewChanged事件

Ira*_*ili 0 javascript jquery single-page-application durandal durandal-2.0

我如何在shell.js中监听视图更改事件?

我想在新视图激活时为标记生成href

我正在使用Durandal 2.x.

Gar*_*y F 5

您可以尝试订阅shell.js中路由器的activeInstruction observable

define(['plugins/router', 'durandal/app'], function (router, app) {

    router.activeInstruction.subscribe(function (configObject) {
        console.log('activeInstruction', configObject);
    });
Run Code Online (Sandbox Code Playgroud)

...

这将为您提供一个配置对象,其中包含有关您导航位置的信息.不确定这是否是最好的方法,或者即使它被设计为以这种方式使用但看看,它可能会有所帮助.