AngularJS "#!" on url

All we need is an easy explanation of the problem, so here it is.

someone knows what “#!” Means. on the url?

I was working until then this appears,I had a “#” always in the url and would like to keep it that way.
Currently routing is not working anymore,probably because of this url change.

It’s part of a business project, i don`t want to change to html5Mode.

I tried to use:

$locationProvider.hashPrefix("");

Even correcting the url in this way routing is having problems

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Thats called hash-bang.

To fix this use :

    angular.module('yourApp', [])
    .config(['$locationProvider', function($locationProvider) {
        $locationProvider.hashPrefix('');
    }]);

Adding html5Mode would even get rid of the ‘#’ in the url but if you refresh the page, then you would get a 404 error. This can be fixed by configuring your server a bit. For that you might want to check the nice little tutorials :

  1. https://scotch.io/tutorials/pretty-urls-in-angularjs-removing-the-hashtag
  2. https://www.theodo.fr/blog/2017/01/pretty-url-in-angularjs-and-loopback-drop-the/

There is another answer to the hashbang issue in stackoverlow :

Doing links like Twitter, Hash-Bang #! URL's

Method 2

You can use html5Mode in your location provider.

$locationProvider.html5Mode(true);

more info https://scotch.io/tutorials/pretty-urls-in-angularjs-removing-the-hashtag

Method 3

Set html5mode true in your app.config

$locationProvider.html5Mode(true).hashPrefix('*');

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply