Why is there #! in the url of my angular app

后端 未结 2 837
青春惊慌失措
青春惊慌失措 2020-12-19 13:40

for some unknown reason, I have \'#!\' added to my apps url when debugging in visual studio 2015.

urls look like this

http:         


        
相关标签:
2条回答
  • 2020-12-19 14:32

    You should apply this in order to not to have hash bang for angular

    $locationProvider.html5Mode({
      enabled: true,
      requireBase: false
    });
    
    <head>
      <base href="/">
      ...
    </head>
    

    for angular 2, this is enough, I think:

    <base href="/" />
    

    Per your comment it seems some how you switch Hashbang Mode

    Configuration:

    $routeProvider
      .when('/path', {
        templateUrl: 'path.html',
    });
    $locationProvider
      .html5Mode(false)
      .hashPrefix('!');
    

    Please see this

    0 讨论(0)
  • 2020-12-19 14:33

    I have found this in angualr 1.6.0 changelog

    $location: default hashPrefix to '!' (aa077e, #13812)

    changelog: https://github.com/angular/angular.js/blob/master/CHANGELOG.md

    change: https://github.com/angular/angular.js/commit/aa077e81129c740041438688dff2e8d20c3d7b52

    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.

    to revert to the old way just use

    appModule.config(['$locationProvider', function($locationProvider) {
        $locationProvider.hashPrefix('');
    }]);
    
    0 讨论(0)
提交回复
热议问题