Link to fragment of the current page

There are some situations on the website I'm working on where the content author wants to link to other spots on the same page.

I already have code in place to add fragment anchors (IDs) to section headings.

The content author would like to, as part of rich text fields, have inline links which point to those anchors.

It can't be a Document link, because there's no way in the Prismic UI to tell such a link that you want to add a #fragment-name to the end of its URL.

It seems like it ought to be possible using the web link type, and filling in the URL as #fragment-name. However, Prismic insists on prefixing it with https://, which leads to a broken link https://#fragment-name.

Now, in my code I expect I can look for this and strip it out so that it works. But that shouldn't be necessary.

This seems like a bug, blocking users from using a useful feature (even if it's an unintended one).

Please just give back the URLs as they were entered.

Exactly the same solution would also allow links to fragments of other pages on the same site, by entering the URL as /url-to-page/#fragment-name, which would also be extremely useful in lieu of a dedicated "fragment name" field added to the Prismic UI for document links.

Currently when entering URLs as above, Prismic is adding the https:// prefix, just like for same-page fragment links.

I've worked around it in my code: I look for a URL where /^https:\/\/[/#]/.test(url) is true, and if so I strip the first 8 characters from it.

Hey Bart,

Sorry about the delay in the reply.

I think this is a strong use case for removing the enforced https:// prefix. So I'm opening up the discussion with the Product Team to see what their opinion is on this. I'll let you know what the response is as soon as I do.

Also, thank you for sharing your workaround for this :slight_smile:

1 Like

So I got a response from the team regarding this.

Yes this has been considered and we should do it. We're just postponing for now as we will roll it in to the larger body of work which will be revamping the document writing UI.

So you can expect it when that project will start, although there's no timeframe for that right now.