-
Notifications
You must be signed in to change notification settings - Fork 27.4k
$location.hash inserts two hash signs #13812
Comments
You can use var url = $location.absUrl(); |
This is due to the fact that the default location mode is The simple workarounds are:
|
The differences between html5 and hashbang mode are detailed in the dev guide (in case you haven't read that already). This pretty much expected behavior. |
@gkalpak - do you think we ought to make a BC in 1.5.0 and change the default |
@gkalpak I'm not using any type of routing. It's a true singlepage application I'm working on, that just needs to store a search query in the url. @petebacondarwin Would html5Mode not cause the hash sign to disappear completely? html5Mode usually requires changes at the server level (rewriting urls and stuff) which in our case is not an option... The hashPrefix isn't a real elegant workaround, I hope you agree. I would like to keep the url as elegant as I can with the restriction I mentioned. |
If you are not doing routing and you never change the |
true singlepage applications do have client-side routing (unless you mean it's just a single page 😃).
Why are you using
If there is indeed no client-side routing involved, then html5 should not need any configuration on the server.
It would make the 1st hash disappear, not both of them. @petebacondarwin: It would have made sense for |
The $location service is designed to support hash prefixed URLs for cases where the browser does not support HTML5 push-state navigation. The Google Ajax Crawling Scheme expects that local paths within a SPA start with a hash-bang (e.g. `somedomain.com/base/path/#!/client/side/path`). The `$locationProvide` allows the application developer to configure the hashPrefix, and it is normal to set this to a bang '!', but the default has always been the empty string ''. This has caused some confusion where a user is not aware of this feature and wonders why adding a hash value to the location (e.g. `$location.hash('xxx')`) results in a double hash: `##xxx`. This commit changes the default value of the prefix to '!', which is more natural and expected. See https://developers.google.com/webmasters/ajax-crawling/docs/getting-started Closes angular#13812 BREAKING CHANGE The hash-prefix for `$location` hash-bang URLs has changed from the empty string "" to the bang "!". If your application does not use HTML5 mode or is being run on browsers that do not support HTML5 mode, and you have not specified your own hash-prefix then client side URLs will now contain a "!" prefix. For example, rather than `mydomain.com/#/a/b/c` will become `mydomain/#!/a/b/c`. If you actually wanted to have no hash-prefix then you should configure this by adding a configuration block to you application: ``` appModule.config(['$locationProvider', function($locationProvider) { $locationProvider.hashPrefix(""); }]); ```
The $location service is designed to support hash prefixed URLs for cases where the browser does not support HTML5 push-state navigation. The Google Ajax Crawling Scheme expects that local paths within a SPA start with a hash-bang (e.g. `somedomain.com/base/path/#!/client/side/path`). The `$locationProvide` allows the application developer to configure the hashPrefix, and it is normal to set this to a bang '!', but the default has always been the empty string ''. This has caused some confusion where a user is not aware of this feature and wonders why adding a hash value to the location (e.g. `$location.hash('xxx')`) results in a double hash: `##xxx`. This commit changes the default value of the prefix to '!', which is more natural and expected. See https://developers.google.com/webmasters/ajax-crawling/docs/getting-started Closes angular#13812 BREAKING CHANGE The hash-prefix for `$location` hash-bang URLs has changed from the empty string "" to the bang "!". If your application does not use HTML5 mode or is being run on browsers that do not support HTML5 mode, and you have not specified your own hash-prefix then client side URLs will now contain a "!" prefix. For example, rather than `mydomain.com/#/a/b/c` will become `mydomain/#!/a/b/c`. If you actually wanted to have no hash-prefix then you should configure this by adding a configuration block to you application: ``` appModule.config(['$locationProvider', function($locationProvider) { $locationProvider.hashPrefix(""); }]); ```
The $location service is designed to support hash prefixed URLs for cases where the browser does not support HTML5 push-state navigation. The Google Ajax Crawling Scheme expects that local paths within a SPA start with a hash-bang (e.g. `somedomain.com/base/path/#!/client/side/path`). The `$locationProvide` allows the application developer to configure the hashPrefix, and it is normal to set this to a bang '!', but the default has always been the empty string ''. This has caused some confusion where a user is not aware of this feature and wonders why adding a hash value to the location (e.g. `$location.hash('xxx')`) results in a double hash: `##xxx`. This commit changes the default value of the prefix to '!', which is more natural and expected. See https://developers.google.com/webmasters/ajax-crawling/docs/getting-started Closes angular#13812 BREAKING CHANGE The hash-prefix for `$location` hash-bang URLs has changed from the empty string "" to the bang "!". If your application does not use HTML5 mode or is being run on browsers that do not support HTML5 mode, and you have not specified your own hash-prefix then client side URLs will now contain a "!" prefix. For example, rather than `mydomain.com/#/a/b/c` will become `mydomain/#!/a/b/c`. If you actually wanted to have no hash-prefix then you should configure this by adding a configuration block to you application: ``` appModule.config(['$locationProvider', function($locationProvider) { $locationProvider.hashPrefix(""); }]); ```
The $location service is designed to support hash prefixed URLs for cases where the browser does not support HTML5 push-state navigation. The Google Ajax Crawling Scheme expects that local paths within a SPA start with a hash-bang (e.g. `somedomain.com/base/path/#!/client/side/path`). The `$locationProvide` allows the application developer to configure the hashPrefix, and it is normal to set this to a bang '!', but the default has always been the empty string ''. This has caused some confusion where a user is not aware of this feature and wonders why adding a hash value to the location (e.g. `$location.hash('xxx')`) results in a double hash: `##xxx`. This commit changes the default value of the prefix to '!', which is more natural and expected. See https://developers.google.com/webmasters/ajax-crawling/docs/getting-started Closes angular#13812 BREAKING CHANGE The hash-prefix for `$location` hash-bang URLs has changed from the empty string "" to the bang "!". If your application does not use HTML5 mode or is being run on browsers that do not support HTML5 mode, and you have not specified your own hash-prefix then client side URLs will now contain a "!" prefix. For example, rather than `mydomain.com/#/a/b/c` will become `mydomain/#!/a/b/c`. If you actually wanted to have no hash-prefix then you should configure this by adding a configuration block to you application: ``` appModule.config(['$locationProvider', function($locationProvider) { $locationProvider.hashPrefix(""); }]); ```
All our routes now have !# which has broken some links. I take it this is a breaking change? |
Yes, I've literally just stumbled on this too. It breaks the Yeoman generated project that I just created, which had all the same settings as one made only fairly recently (but presumably that will have been before the BC went out) You're probably all much better devs than me 😄 , but for anyone else who stumbles on this and simply wants to undo the BC, it's just a matter of putting this in the .config: .config(function ($routeProvider, $locationProvider) {
...
// undo the default ('!')
$locationProvider.hashPrefix('');
}); |
Yes this is a breaking change. See |
When on the url
index.html
when I set the hash at some point to, say,"foo=bar"
, the url gets two hashes in it.So, as part of a click handler or something (doesn't really matter):
The url becomes:
But we should expect:
This is Angular 1.4.8 on Firefox 43 on Windows 10.
Also happens in Chrome 47, IE11, and Edge 13.
The text was updated successfully, but these errors were encountered: