I am using backbone to build my web app.
Currently I am facing an issue whereby if I am on the home page, I am unable to refresh the same page by just clicking on the 'home' button again.
I believe that this is the limitation provided by backbone (does not reload the page if the same URL is called)
Is there any way around this? So that I can trigger a page reload when I click on the home button again i.e. call the same URL again?
The difference between http://localhost.com/ and http://localhost.com/#!/ is that the second is a link to anchor, it does not load a page, it only looks for the anchor in the current page, and scrolls to it if found. You need to make your link looks like the first one, no "#" close to end.
The backbone.history.loadUrl is the solution.
The click handling function of your Home button (if the home is the root / of your WebApp) should be:
Here's my favorite approach so far:
This is not upto backbone. The same works fine in chrome(webkit browsers), but not in firefox. Its a browser behavior
Looking at the backbone.js source, it seems as though this is not possible by default, since it only responds to a url change. And since clicking the same link, you would not trigger a change event.
Code in Backbone.History:
You'll need to handle a non-change yourself. Here's what I did:
I needed to 'refresh' my page on orientation change event because not all of my css media queries for portrait mode where executed correctly by default. This is what I ended up doing:
Of course, for the completeness of this answer, this was wrapped in some orientation change handling code: