2

Just need to know whether it is a good or not to have a leading slash in your hash url. For instance,

site.come/#/directore/file/

or

site.come/#directore/file/

I am asking this because backbone.js does not recommend the first option in their docs (personally I prefer the first option...),

http://backbonejs.org/#Router-extend

Note that you'll want to avoid using a leading slash in your route definitions

So I want to make sure what the reasons are behind this that you want to avoid using a leading slash.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Run
  • 54,938
  • 169
  • 450
  • 748

3 Answers3

1

I think both methods are bad if the website should be public, as it would hurt SEO.

Conisder using #! as google instructs people to do so that the website is crawlable

eric.itzhak
  • 15,752
  • 26
  • 89
  • 142
1

The main problem that I can think of (referencing this post) is incompatibilities if you decide to use Backbone.history.start({pushState: true})

Consider this setup:

Backbone.Router.extend({
  routes: {
    "/test": "test"
    "test": "test2"
  }
});

The history api is still not set in stone so how it treats and calls routes with slashes is inconsistent - but you should expect history.pushState('/test') to call route test. However, now if you're on a browser that is using the hash fallback it will call route /test/. Therefore, its probably better to avoid the first slash altogether as there is no good way of telling where this will take you without handling both cases:

app.navigate("/test")

Also this is a possible duplicate of Backbone.js slash after hash in fallback - history pushState

Community
  • 1
  • 1
megawac
  • 10,953
  • 5
  • 40
  • 61
1

I would prefer the first one as this keep the URL more clean. Even AngularJS routing system prefers the first one. like:

site.com/#/directory/file

for SEO purpose, both doesn't have any meaning at all. Yes, thats right, hitory API uses #! in their URL formation system.

Ashish Kumar
  • 2,991
  • 3
  • 18
  • 27