我正在尝试扩展这个方便但基本的反馈小部件: http://experiments.hertzen.com/jsfeedback/
它位于窗口命名空间中并 POST 到 Blob 服务器。我希望能够查看我的 Durandal 应用程序的路由器历史记录,并使用我的常规反馈对象发送回快照。
有人可以建议如何做到这一点吗?
注意:由于 Durandal 2.0 路由器与 Backbone.js 类似,因此 Backbone 开发人员的建议也可能会有所帮助。
我正在考虑这样的事情:
durandalRouter.on('路由器:导航:组合完成')
.then((实例: 字符串, 指令: DurandalRouteInstruction, 路由器: DurandalRouter) => {
//待办事项:跟踪历史记录...
});
最佳答案
你基本上已经得到答案了。您可以实例化一个数组,最好作为模块,但也可以作为全局变量:
window.appHistory = [];
然后。您可以在路由器上设置事件监听,将指令参数附加到历史记录中。
router.on('router:navigation:complete')
.then(function(instance, instruction, router) => {
appHistory.push(JSON.stringify(instruction));
};
指令对象看起来像这样。
{
"fragment": "",
"queryString": null,
"config": {
"title": "Home",
"route": "",
"moduleId": "viewmodels/home",
"hash": "#",
"routePattern": {}
},
"params": [],
"queryParams": null
}
关于javascript - 如何: Get Durandal (or Backbone) router history and pass to window.一些全局变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28552145/