AngularJS: How to remove #!/ (bang prefix) from URL?

后端 未结 6 1375
不思量自难忘°
不思量自难忘° 2020-12-03 15:29

I already have done $locationProvider.html5Mode(true); but it is not working. Whenever I access http://example.com it goes to http://example.

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 16:05

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

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

    Source here for more information.


    Update

    If you want to remove the whole prefix (# and not only !), you may try this solution:

    1) Activate the HTML5 mode and remove the prefix ! in your module config

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

    2) And then set base to / in the on your index.html

    
        ...
        
    
    

提交回复
热议问题