AngularJS是把斜杠(/)哈希标签之后 [英] AngularJS is putting forward slash / after hash tag

查看:581
本文介绍了AngularJS是把斜杠(/)哈希标签之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用AngularJS $ anchorScroll $的location.hash 。但是,当我设置散列,AngularJS增加了一个斜线,/后。

例如,URL为:的http://本地主机:13060 /仪表板。当我不包括AngularJS库,我可以点击该链接, #contact ,然后转到的http://本地主机:13060 /仪表板#contact

但是,当我有AngularJS并点击链接,它进入的http://本地主机:13060 /仪表板#/联系 preventing $ anchorScroll无法正常工作。

修改$ anchorScroll不工作


起始URL是的http://本地主机:13060 /类别
当我添加的类别,就应该到的http://本地主机:13060 /分类#/#标识(其中id是新的ID)和向下滚动页面,以它。网址正确更新,但$ anchorScroll不滚动。

  //跳转到新的类别
 $ location.path();
 $的location.hash(cat.ID);
 $ anchorScroll();


解决方案

除非你使用html5mode,从角路由删除哈希,你将有2哈希,一个棱角分明的路由和其他的锚。

的http://本地主机:13060 /仪表板#/#接触

假设你有一个路由路径设置为 /型材和锚是该视图中的URL看起来像:

的http://本地主机:13060 /仪表板#/型材#接触

I'm trying to use AngularJS $anchorScroll with $location.hash. However, when I set the hash, AngularJS adds a forward slash, / after it.

For example, the url is: http://localhost:13060/Dashboard. When I don't include the AngularJS library, I can click the link, #contact, and go to http://localhost:13060/Dashboard#contact.

But when I include AngularJS and click the link, it goes to http://localhost:13060/Dashboard#/contact preventing $anchorScroll from working.

Edit $anchorScroll not working

The starting URL is http://localhost:13060/Category. When I add a category, it should go to http://localhost:13060/Category#/#id (where id is the new id) and scroll down the page to it. The URL is correctly updating but $anchorScroll is not scrolling.

 //jump to new category
 $location.path("");
 $location.hash(cat.ID);
 $anchorScroll();

解决方案

Unless you use html5mode, which removes the hash from angular routing, you will have 2 hashes, one for angular routing and other for anchors.

http://localhost:13060/Dashboard#/#contact

Assuming you had a route path set as /profiles and anchor was in that view the url would look like:

http://localhost:13060/Dashboard#/profiles#contact

这篇关于AngularJS是把斜杠(/)哈希标签之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆