本文介绍了防止$ anchorScroll修改网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<body>
    <header id="brand">
        <!--Content-->
    </header>
</body>

AngularJS代码:

AngularJS code:

$location.hash("brand");
$anchorScroll();

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

However, after $anchorScroll runs, the page url becomes http://localhost:8080/##brand, which means ##brand is appended to the original url. How can I keep the original url when using $anchorScroll? Thanks in advance!

推荐答案

至少在 html5mode 已打开.

(do not call $location.hash())
$anchorScroll('brand');

这篇关于防止$ anchorScroll修改网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 16:23