Can you set it so this fallsback to using # in IE? Is it as simple as just wrapping $locationProvider.html5Mode(true); in if !(IE lt 10) ?
–
Andy HaydenAug 14 '13 at 15:07

23

So this solution does solve removing the hashtag in the url given the url has a hashtag, however it doesn't solve how to respond to requests that doesn't want the hashtag to be included in the first place. Aka, it solves blah/#/phones -> blah/phones but it doesn't handle blah/phones directly.
–
LukeFeb 12 '14 at 1:56

2

@Mik Cox, I was actually able to solve it. Have your backend send back index.html for all URLs, that way you won't be seeing 404s.
–
LukeApr 16 '14 at 2:57

This might be better suited as a comment as it doesn't directly answer the question.
–
remusDec 7 '13 at 7:50

20

According to the developer guide, this detection is done automatically: If the HTML5 History API is not supported by a browser, the $location service will fall back to using the hashbang URLs automatically
–
IanBMar 26 '14 at 0:10

Worked like a charm, and I appreciate method checking rather than browser version checking--future proof.
–
shaneeMay 26 '14 at 0:59

Also if you use Web Api and IIS, this match url will not work out, as it will change your api calls. So add third input(third line of condition) and give out a pattern that will exclude calls from www.yourdomain.com/api

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.