I have a Rails app that I'm using with Backbone JS as a FE framework with Coffeescript syntax. Now to get to the point quickly I'm using a Backbone trick than replaces Rails's redirect_to
method:
redirectTo = (something) ->
Backbone.history.navigate('')
Bacbkone.history.navigate("##{something}", {trigger: true})
And whenever I need a full refresh to my page for example when I'm creating something I use it(this is maybe a wrong approach but I'm new to Backbone). Now I also use localStorage["something"] to store values that I'll use for later. I also have a function:
$(window).on 'hashchange', ->
window.localStorage.clear()
Here is the strange part. For example I redirect to a #products page with redirectTo('products')
by some logic the localStorage needs to be cleared and I should not be able to use his values in the Router. But the funny part is I can cause it first goes to the action '#products'
from the Backbone Router and then triggers the $(window).on('hashchange')
. Any clues how can this happen and if this is something regular?