本文介绍了BackboneJS + codeigniter pushState的真不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这样的骨干网应用程序,我使用的后端codeigniter。出于某种原因, pushState的:真正的不起作用

So I have this Backbone App where I use Codeigniter for the Backend. For some reason, pushState:true does not work.

所以,我的我的骨干应用程序的main.js有这样:

So, my main.js of my backbone app has this:

Backbone.history.start({ pushState: true, root: App.ROOT });

我app.js有这样:

My app.js has this:

var App = {
    ROOT: '/projects/mdk/'
};

和我的导航模块,这使得menulinks,每个项目都有这样的:

and my navigation module, which renders the menulinks, each item has this:

this.insertView(new ItemView({
model: new Navigation.ItemModel({
    href: App.ROOT + 'home',
    class: 'home',
    triggers: 'home',
    route: this.route
   })
}));

和型号为它:

Navigation.ItemModel = Backbone.Model.extend({
    defaults: {
        href: '',
        text: '',
        triggers: [],
        route: ''
    }
});

所有我从这个得到的是找不到网页...

All I get from this is "Page not found"...

添加:当我在它的视图切换到的href:#新闻 - 它的工作原理,但它并不真正有意义。 ..

Add: When I in the view change it to href:'#news' - it works, but it dont really makes sense...

任何人谁知道这里的​​问题?

Anyone who knows the issue here?

推荐答案

好,我找到了一个解决方案通过自己:

ok I found a solution by myself:

我做了这个技巧:

$(document).on('click', 'a:not([data-bypass])', function (evt) {

    var href = $(this).attr('href');

        if (href && href.indexOf('#') === 0) {
            evt.preventDefault();
            Backbone.history.navigate(href, true);
        }
    });

然后我做了:

href: '#home',

这解决了这个问题,现在evereythings运行流畅。

That solved the problem, now evereythings runs fluently..

这篇关于BackboneJS + codeigniter pushState的真不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 10:27