Removing the fragment identifier from AngularJS urls (# symbol)

后端 未结 14 2010
Happy的楠姐
Happy的楠姐 2020-11-22 00:01

Is it possible to remove the # symbol from angular.js URLs?

I still want to be able to use the browser\'s back button, etc, when I change the view and will update th

14条回答
  •  无人共我
    2020-11-22 00:43

    You can tweak the html5mode but that is only functional for links included in html anchors of your page and how the url looks like in the browser address bar. Attempting to request a subpage without the hashtag (with or without html5mode) from anywhere outside the page will result in a 404 error. For example, the following CURL request will result in a page not found error, irrespective of html5mode:

    $ curl http://foo.bar/phones
    

    although the following will return the root/home page:

    $ curl http://foo.bar/#/phones
    

    The reason for this is that anything after the hashtag is stripped off before the request arrives at the server. So a request for http://foo.bar/#/portfolio arrives at the server as a request for http://foo.bar. The server will respond with a 200 OK response (presumably) for http://foo.bar and the agent/client will process the rest.

    So in cases that you want to share a url with others, you have no option but to include the hashtag.

提交回复
热议问题