URL hash-bang (#!/) prefix instead of simple hash (#/) in Angular 1.6

JavascriptAngularjsUrlHashbangAngularjs 1.6

Javascript Problem Overview


My URLs on an AngularJS project have changed from localhost:3000/admin#/ to localhost:3000/admin#!/ since the last time I worked on my project...

Nothing found on the web, does someone know what this is ?

Javascript Solutions


Solution 1 - Javascript

It is new from AngularJS 1.6, which added a new hash prefix.

> Due to aa077e8, the default hash-prefix used 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 the URL will become > mydomain.com/#!/a/b/c.

Source here for more information.


If you want to remove this prefix, add this code to your config:

appModule.config(['$locationProvider', function($locationProvider) {
  $locationProvider.hashPrefix('');
}]);

Solution 2 - Javascript

Everyone is proposing to remove the prefix, but you could also simply add a ! to client-side URLs (if not using HTML5 mode, which you probably do if you're here).

So in your client-side files, update URLS like this:

#/foo/bar > #!/foo/bar

Solution 3 - Javascript

In Angular 1.6.0, the default hashPrefix has been changed to !. See the related commit and the changelog entry.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPierre C.View Question on Stackoverflow
Solution 1 - JavascriptMistalisView Answer on Stackoverflow
Solution 2 - JavascriptOverdrivrView Answer on Stackoverflow
Solution 3 - JavascriptDevDigView Answer on Stackoverflow