BackboneJS+Rails - what to do on a browser refresh/reload?

So I setup a wizard type form using BackboneJS on a Rails 4 application. As I’m stepping through the wizard (via the Backbone router url’s: formwizard/1, formwizard/2, etc.), a rails routing error would occur if the user refreshed the page.

To fix this, in my Rails app routes.rb file, I setup a route similar to:

get ‘formwizard/:id’, controller: :wizard_controller, action: :index

Within the index view, I have some inline coffeescript such as:

:coffeescript
  $ ->
    new Form.Routers.WizardForm
    Backbone.history.loadUrl("formwizard/1")

So if a user reloads the page when the url bar reads formwizard/2, it reloads the page and refreshes it as if it was on formwizard/1 state. The url in the bar never changes from http://localhost…formwizard/2 to http://localhost…formwizard/1.

This feels a little bit hackey to me. Is there a good way/best practice to intercept a page reload/refresh request from the browser and then reload the correct backbone view corresponding to the route?

2 approaches I found that might pass muster:

  1. window.onload = $.address.update(function(){    
    


    })

  2. <body onLoad="JavaScript: checkRefresh();" onUnload="JavaScript: prepareForRefresh();">
    reference