简体   繁体   中英

Angular how to keep hashtag in html5 mode

In Angular router, if you turn on html5 mode, you automatically remove the hashtags in urls, which is great. But what, if you want to keep hashtags for non router related things, for example, if you want to scroll to an image with a specific id?

www.example.com#imageId becomes www.example.com/imageId, which is not the desired effect.

If you are only concerned with anchor scrolling, you don't necessarily need url location hashtags to scroll to elements. You can use $anchorScroll('elementId') inside a controller method to do that. I just did this yesterday in a project at work.

Angular Docs Link to $anchorScroll

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM