Skip to content

In combination with turbolinks getting error  #134

Description

@pbrazdil

Backbone-rails isn't compatible with Turbolinks gem, which it will has to be since turbolinks gem going to be in Rails 4.0

When I load page and then click on some link which will be processed by turbolinks, getting error below

Uncaught Error: Backbone.history has already been started

Activity

  1. hyperrjas commented on Mar 7, 2013

    @hyperrjas

    I have the same problem +1

  2. hyperrjas commented on Mar 7, 2013

    @hyperrjas

    I have fixed the problem. I don't know if this is correct:

    initialize: ->
      new MyApp.Routers.Posts
      Backbone.history.start() unless Backbone.History.started
      $(document).on "page:change", ->
        Backbone.history.stop()
        Backbone.history.start()
    

    Please correct me if I'm wrong. thanks

  3. carlosmoralesla commented on Aug 25, 2016

    @carlosmoralesla

    I tried your code but seems not to be running.
    Are you sure that "initialize: ->" code is correct?

    initialize: ->
    new MyApp.Routers.Posts
    Backbone.history.start() unless Backbone.History.started
    $(document).on "page:change", ->
    Backbone.history.stop()
    Backbone.history.start()

  4. pbrazdil commented on Aug 25, 2016

    @pbrazdil
    Author

    It's 3 years old
    čt 25. 8. 2016 v 6:50 odesílatel Carlos Morales notifications@github.com
    napsal:

    I tried your code but seems not to be running.
    Are you sure that "initialize: ->" code is correct?

    initialize: ->
    new MyApp.Routers.Posts
    Backbone.history.start() unless Backbone.History.started
    $(document).on "page:change", ->
    Backbone.history.stop()
    Backbone.history.start()

    —
    You are receiving this because you authored the thread.
    Reply to this email directly, view it on GitHub
    #134 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe-auth/ABYDLfvcGnMZM4szmsTAwzIJQdrCduSoks5qjR8PgaJpZM4AUBDl
    .

  5. DanTaiko commented on Aug 26, 2017

    @DanTaiko

    I had the same problem.
    The solution of @hyperrjas should be workable, unless turbolink is set.

    With 'turbolink' I got the following possible solution that works for me (enviroment: Rails v5.1.1, jQuery v3.2.1, Backbone 1.2.0):

    initialize: ->
        new MyApp.Routers.Posts
        Backbone.history.start() unless Backbone.History.started
        $(document).on "turbolinks:click", ->
          Backbone.history.stop() 
    

    Or even more simple one, depending of your need:

    initialize: ->
        new MyApp.Routers.Posts
        Backbone.history.start() unless Backbone.History.started
    

    I don't think it's a Backbone-rails bug, it lies in understanding of the Backbone.routing and Turbolink events.

    Hope it will be helpfull to someone. ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions