注入 $location 服务使我的 url 与片段标识符变得奇怪

Injecting $location service makes my url with fragment identifier weird

这是我的 angular 代码

var app = angular.module('app', []);
app.controller('mainController', ['$location', '$scope', '$log', function(location, scope, log) {
    log.info(location.path());
}]);

这是我的 html

<div ng-controller="mainController">
    <h1>Sample</h1>
    <a href="#link">Go to Link</a>
    <p id="link">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </p>
</div>

现在单击我的 html 中使用的 'Go to link' 后,url 指的是 localhost/angular/#!#link 而不是 localhost/angular/#link

事实上,在将“$location”服务注入 angular 应用程序后,任何带有片段标识符的 url 都会转到 localhost/angular/#!#url。为什么会导致 /#!#url 而不是 /#url

我正在使用 AngularJS v1.6.1

正如 nivas 之前提到的,请查看您的代码,您是否有这样一行

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