4

Given:

  • Tom — who has a modern browser which is pushState-enabled
  • Fred — who has a browser which is not pushState-enabled
  • a super.app web application powered by Backbone

Tom browses to products/1 page where a #special-offer section exists.

Does Backbone allow Tom to share a link with Fred including the anchor to the special-offer section: http://super.app/products/1#special-offer

Will Fred be redirected to http://super.app/#products/1 (eg: without the #special-offer)?

In other words, does Backbone allow to use anchors?

abernier
  • 27,030
  • 20
  • 83
  • 114

2 Answers2

4

I had a test here http://bl.ocks.org/abernier/raw/3183257/

It appears that YES:

  • anchors can be used with pushState-enabled browsers : http://bl.ocks.org/abernier/raw/3183257/product1.html#special-offer
  • while for IE<10, it is converted to http://bl.ocks.org/abernier/raw/3183257/#product1.html eg: without #special-offer

The only thing I had to take care about was to disable anchors for hashes-based history browsers, by:

if (!Backbone.history._hasPushState) {
  $('body').delegate('a[href^=#]', 'click', function (e) {
    e.preventDefault();
  });
}
abernier
  • 27,030
  • 20
  • 83
  • 114
0

Backbone has a very customizable use of hash URL fragments within its modules Router and History.

fguillen
  • 36,125
  • 23
  • 149
  • 210
  • 1
    Funny thing is there are anchors in your links :) but unfortunately, Backbone's documentation you're referring here doesn't deal with anchors. So it leaves my question unanswered... – abernier Jul 26 '12 at 15:56
  • I have been using _hash-based URL fragments_ in old Backbone projects, so I think it supports it, maybe I'm understanding wrong your _URL anchor_ description but I think I don't. The documentation in my links is almost hiding the comments about _hash-based URL fragments_ because it is adding more importance to the use of [HTML5 history API](http://diveintohtml5.info/history.html), but you can read _"Until recently, hash fragments (#page) were used to provide these permalinks..."_ and _"...the Router handles graceful fallback and transparent translation to the fragment version of the URL"_ – fguillen Jul 26 '12 at 16:17