Using the Backbone.js router to navigate through views modularized with require.js

前端 未结 8 983
别跟我提以往
别跟我提以往 2020-12-22 23:41

I am separating my views and router into separate files with require. I then have a main.js file that instantiates the router, and also renders my default view.

My r

8条回答
  •  没有蜡笔的小新
    2020-12-23 00:27

    You could do it the old fashioned way with window.location.hash :)

    window.location.hash = "Edit/1"
    

    Here's an alternate solution if you don't need explicit routes. When you app starts up create an object that extends Backbone Events

    window.EventDispatcher = _.extend({}, Backbone.Events);
    

    Then anywhere in you app you can listen for events

    EventDispatcher.bind("mymodel:edit", this.editHandler, this);
    

    And also from anywhere dispatch the event, data below are any params you want to send along for the ride

    EventDispatcher.trigger("mymodel:edit", data);
    

提交回复
热议问题