Frage

i would like to use Routes with navigate but i have an error.

(function(){

window.App = {
    Models: {},
    Collections: {},
    Views: {},
    Routers: {}
};

App.Router = Backbone.Router.extend({
    routes: {
        "/case-projet/:projet": "caseProjet"
    },
    showPage: function(page){
        //hide all pages
        this.hidePages();
        //show passed page by selector
        $(page).show();
    },
    caseProjet: function (e) {
        this.showPage('div#partech-introduction');
    }

});

new App.Router;
Backbone.history.start();

App.Views.Incentive = Backbone.View.extend({
    el: $("#projet-page"),
    caseStudyContainer: $("#projet-page"),
    caseStudyElem: $('section[data-projet-page="Incentive"]'),
    initialize: function () {
        $("#Incentive a.OpenProject").on("click", this.enterProjectAnim)
    },
    enterProjectAnim: function () {
        var e = this;
        App.Router.navigate("/case-projet/Incentive", {trigger: true})
        , $("#homepage").css("display", "none")
        , e.caseStudyElem.css({ display: "block" })
        , $("#partech-introduction").addClass("active")
    }
});

})();

In Chrome Dev Tools:

Uncaught TypeError: Object function (){ return parent.apply(this, arguments); } has no method 'navigate'

i tried with the response of Backbone Router has no method navigate but this does not work.

Why have i this error ?

Tks :)

War es hilfreich?

Lösung

Change the call App.Router.navigate(...) to Backbone.history.navigate(...).

Alternatively, you could set a variable to the new App.Router() instance you create, and then call the navigate function on that instance. Your code is trying to call the navigate on the class definition; you need an instance of the class instead.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top