gpt4 book ai didi

javascript - Backbone : before route

转载 作者:行者123 更新时间:2023-11-29 18:20:04 25 4
gpt4 key购买 nike

google 上有很多主题,但没有任何完整且有效的示例。

我如何包装路由器的导航,以便我可以检查条件并在需要时取消导航?

附言我看到了 _.wrap 的想法,覆盖 Backbone.Router.prototype.route 等,但没有完整的例子。我也看到了 backbone-route-filter但不知道如何将它集成到我的应用程序中。

最佳答案

您可以尝试覆盖 Backbone.history.route:

var bbhRoute = Backbone.history.route;
Backbone.history.route = function(route, callback) {
return bbhRoute.call(Backbone.history, route, function(fragment) {
// if (decide if you want to prevent navigation) {
// window.history.back(); // to ensure hash doesn't change
// return;
// }

// if you want to let it happen:
return callback.apply(this, arguments);
});
};

关于javascript - Backbone : before route,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19569154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com