在我的viewmodel类中,如何获取对当前路由器的引用?
我真正想做的是获取当前的ModuleId。
在Durandal中,有system.getModuleId,但Durandal中没有系统,所以我认为路由器将会有这些信息。
答案 0 :(得分:2)
访问当前moduleId
的一种方法(不确定,最佳方法)位于班级的activate
钩子中:
activate(params, routeConfig) {
console.log(routeConfig.moduleId);
}
答案 1 :(得分:2)
获取对当前路由器的引用的方法:
import {inject} from 'aurelia-framework'
import {router} from 'aurelia-router'
@inject(router)
constructor(router)
{
this.router = router; //Do something with router.
}
注意:不要注入“AppRouter”它是一个不同的路由器。如果您添加到AppRouter的路由,它将无法正常工作。如果您导入路由器,它将起作用。