Durandal:确定视图当前是否处于活动状态(可能使用路由器)?

Rob*_*ous 3 durandal

我的shell有按钮,只有当用户当前正在查看某个viewModel时才应显示这些按钮.如何确定视图当前是否从shell"处于活动状态"?

Rai*_*rit 8

假设在shell.js activate使用中定义路由viewAttached将允许访问该router对象.

return {
    router: router,
    viewAttached: function () {
        console.log('activeRoute', router.activeRoute());
    },
    activate: function () {
        router.map([...
Run Code Online (Sandbox Code Playgroud)

根据评论更新

在Durandal 2.x activeRoute()中不再定义.请router.activeInstruction()改用.

根据评论更新2

在Durandal 2.x viewAttached现在attached.

注意:对于那些需要访问当前路由配置以获取自定义属性或其他信息的人,可以通过router.activeInstruction()访​​问原始数据该指令包含片段,queryString,params和queryParams.它还包含一个config属性,它与原始路由配置的实例相同.

http://durandaljs.com/documentation/Conversion-Guide/