Backbone.js 主干路由器没有方法导航

Backbone.js 主干路由器没有方法导航,backbone.js,router,Backbone.js,Router,只是想知道为什么我的路由器没有导航方法 我有新的应用程序。路由器;正确地呼叫。在我看来,我尝试这样调用我的索引视图: addTrip: function(e){ e.preventDefault() ; //Adding to collection var newTrip = this.collection.create({ title: this.$('#new_trip #title').val(), where: this.$('

只是想知道为什么我的路由器没有导航方法

我有新的应用程序。路由器;正确地呼叫。在我看来,我尝试这样调用我的索引视图:

addTrip: function(e){

    e.preventDefault() ;

    //Adding to collection
    var newTrip = this.collection.create({
        title: this.$('#new_trip #title').val(),
        where: this.$('#new_trip #where').val(),
        desc: this.$('#new_trip #desc').val(),
        rating: this.$('#new_trip .active').text()
    }, { wait: true })  ;

    if(newTrip.validationError){
        this.errorReport(newTrip.validationError) ;
    }

    this.clearForm() ;

    //Navigate to home route
    App.Router.navigate('', true) ;

}
我在Chrome开发工具中遇到以下错误:

未捕获的TypeError:对象函数{return parent.applythis,arguments;}没有方法“navigate”

我甚至尝试从控制台调用navigate,但它似乎也不起作用


我做错了什么?

您应该在路由器对象上调用navigate。看来你是在课堂上说的

App.myRouter = new Backbone.Router() //or if you have your own base router class App.myRouter = new App.Router() 


myRouter.navigate('', true);

您应该在路由器对象上调用navigate。看来你是在课堂上说的

App.myRouter = new Backbone.Router() //or if you have your own base router class App.myRouter = new App.Router() 


myRouter.navigate('', true);

你如何声明App.Router?你如何声明App.Router?我在index.html中声明了我的路由器,但需要在我的方法中重新声明它。感谢@neebzu使用我仍然无法触发的路由器实例。navigatemyPath。不过,当我调用Backbone.history.navigatemyPath时,它可以工作。我在index.html中声明了路由器,但需要在方法中重新声明它。感谢@neebzu使用我仍然无法触发的路由器实例。navigatemyPath。不过,当我调用Backbone.history.navigatemyPath时,它就可以工作了。