AngularJS prints slash / after hash tag

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

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

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

Edit $ anchorScroll not working

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 identifier) ​​and scroll down to it. The url updates correctly, but $ anchorScroll does not scroll.

  //jump to new category $location.path(""); $location.hash(cat.ID); $anchorScroll(); 
+8
angularjs hashtag anchor-scroll
source share
1 answer

If you are not using html5mode, which removes the hash from angular routing, you will have 2 hashes, one for angular routing and the other for anchors.

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

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

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

+5
source share

All Articles