防止$ anchorScroll修改url

632*_*324 10 url angularjs

我正在使用$anchorScroll滚动到页面顶部html元素具有ID #brand.

<body>
    <header id="brand">
        <!--Content-->
    </header>
</body>
Run Code Online (Sandbox Code Playgroud)

AngularJS代码:

$location.hash("brand");
$anchorScroll();
Run Code Online (Sandbox Code Playgroud)

但是,在$anchorScroll运行之后,页面URL变为http://localhost:8080/##brand,这意味着##brand附加到原始URL.使用时如何保留原始网址$anchorScroll?提前致谢!

Bri*_*ian 13

以其显式形式使用$ anchorScroll似乎有效,至少在html5mode打开时.

(do not call $location.hash())
$anchorScroll('brand');
Run Code Online (Sandbox Code Playgroud)