Marionette.js appRouter不开火的应用程序启动 [英] Marionette.js appRouter not firing on app start

查看:129
本文介绍了Marionette.js appRouter不开火的应用程序启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前木偶集成到现有的应用骨干

I am currently integrating Marionette into an existing Backbone application.

我来代替已有的骨干路由器,但是想实现一个Marionette.AppRouter取代其地位。问题是,在硬刷新关于新的木偶路由器应拿起URL,它不火。如果我浏览到另一个页面,然后再回到未在硬刷新火的网址,它正确地触发。我想不通为什么它工作的 的我已导航到另一个页面,然后再返回之后。这里是我的code样品:<​​/ P>

I have an existing Backbone router in place, but am trying to implement a Marionette.AppRouter to take its place. The problem is that on a "Hard Refresh" on the url that the new Marionette router should pick up, it does not fire. If I navigate to another page, then go back to the url that did not fire on a hard refresh, it fires correctly. I cannot figure out why it works after I have navigated to another page and back again. Here is my code sample:

TestApp = new Backbone.Marionette.Application();
    var testAppController = {
        testLoadPage: function(){
            console.log('testLoadPage Fired'); //<---- DOES NOT FIRE ON HARD REFRESH
        }
    };
    TestAppRouter = Backbone.Marionette.AppRouter.extend({          
        appRoutes: {
            "!/:var/page": "testLoadPage",
            "!/:var/page/*path": "testLoadPage"
        },
        controller: testAppController,
        route: function(route, name, callback) {
            return Backbone.Router.prototype.route.call(this, route, name, function() {
                if (!callback) callback = this[name];
                this.preRoute();
                this.trigger.apply(this, ['beforeroute:' + name].concat(_.toArray(arguments)));
                callback.apply(this, arguments);
            });
        },
        preRoute: function() {
            app.showLoader(name, arguments);
        }
    });
    TestApp.addRegions({
        contentContainer: '#container'
    });
    TestApp.addInitializer(function(options){
        new TestAppRouter();
    });
    TestApp.start();

当我加载页面: http://mysamplesite.com/#!/123/page 直接,木偶路由器不火,因为它应该

When I load the page: http://mysamplesite.com/#!/123/page directly, the Marionette router does not fire as it should.

不过,如果我加载页面: http://mysamplesite.com/#!/123 ,然后导航到的http:// mysamplesite.com /#!/ 123 /页,木偶路由器火灾正确。任何想法?

However, if I load the page: http://mysamplesite.com/#!/123 and then navigate to http://mysamplesite.com/#!/123/page, the Marionette router fires correctly. Any ideas?

推荐答案

你叫 Backbone.history.start()创建你的路由器实例后?如果没有,你需要做的。路由器将无法运行,直到这就是所谓的在你的应用程序,你不能叫,直到至少有一个路线已经被实例化。我通常这样做:

Did you call Backbone.history.start() after creating your router instance? If not, you need to do that. Routers won't run until this is called in your app, and you can't call this until at least one route has been instantiated. I usually do this:


TestApp.on("initialize:after", function(){
  if (Backbone.history){ Backbone.history.start(); }
});

心连心

这篇关于Marionette.js appRouter不开火的应用程序启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆