Hash/anchors are being stripped from URLs on mobile. How to stop that?

When I click on a link with an anchor on desktop, it scrolls there. However on mobile (Android, FF & Chrome) the anchor gets stripped from the url so there is no scrolling to that spot.

What I am trying to do:

We have a long guideline and faq document that need to link to headings. Because Discourse strips out id parameters, I have created a simple theme component that uses custom data attributes in the target document and listens for anchors in the url to scroll to the element with matching data element.

It works on desktop!

However on mobile, the anchors seem to get stripped so that when you get to the target page there is no scrolling to the right element. And of course with a long document Mobile is where you need that navigation the most.

Now, I do find that the anchors generated by the Table of Contents component do work when opening them in a new link. They are not stripped from the url and the browser scrolls to the right place.

How can I get this to work?


(Vent: It has been really frustrating trying to do something so basic and fundamental to HTML, namely have anchors and link to them. I realize that because posts are user created content there are security issues. But it feels like the solutions implemented to protect from abuse are very blunt and make doing something very simple very complicated. That said, my site has never been hacked, so I guess that’s something.)