Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

asp.net - Why is there #! in the url of my angular app

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

urls look like this

http://localhost:58394/#!/customers
http://localhost:58394/#!/

I have searched all app if this is some sort of typo, but I cannot figure out where is this comming from.

I can see that in ASP.NET WEB API as well as in ASP.NET CORE WEB API...

For front end I'm using angular and angular-route 1.6.0

Any ideas where is this comming from?

I'm not using html5mode nor base tag and I'm happy for # to be there for now, I just don't understand why is the exclamation mark (!) in there ...

This app is not to be deployed on web and is not using any external service which could possibly use #! notation for any tracking or anything else.

The exclamation mark started to apear after the hast just recently so I guess this is caused by some the libs I'm using.

I just would like to know why '!'is there and what library it forcing this exclamation there.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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('');
}]);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...