URL fragments: a leading slash in your hash url - good or bad?

北战南征 提交于 2019-12-12 14:36:17

问题


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.


回答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




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/20236463/url-fragments-a-leading-slash-in-your-hash-url-good-or-bad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!