1

I was following the backbonerails.com screencast episode 6. But I can't get the routing to work as it was explained.

Here is my code that is similar to what the screencast suggest:

@Report.module "UsersApp", (UsersApp, App, Backbone, Marionette, $, _) ->

  class UsersApp.Router extends Marionette.AppRouter
    initialize: ->
      console.log "Happy days"
    appRoutes:
      "users"  : "listUsers"

  API =
      listUsers: ->
        console.log "hallo"

  App.addInitializer ->
    console.log "cheers"
    new UsersApp.Router
      controller: API

As you can see I have tried to add console.log in a few places to make sure the addInitializer is working and that the Router is started... but still the routing to #users does not do the corresponding console.log

I have this where I define the app:

  App.on "initialize:after", ->
     if Backbone.history
       Backbone.history.start()

So that should run after router has started, if I understand it all.

1 Answers1

3

Turns out that it was the Backbone history was not running. I found that out by running:

Backbone.History.started

in my console. For some reason

  App.on "initialize:after", ->
    if Backbone.history
      Backbone.history.start()

did not start the history.

EDIT: turns about in v2 and above of Marionette you should use:

  App.on "start", ->
  • Hi Justinus, same situation here I followed the same tutorial, I also realized it was renamed to "start" however could you tell me if you're having a problem when pressing "back" in your browser because I am as described here https://stackoverflow.com/questions/28437115/app-onstart-is-called-again-when-i-press-back-in-the-browser – user391986 Feb 10 '15 at 16:50