Link field relative

Hi James,

I'll be happy to help.

Can you tell me more about how you have configured your dev and staging environments?
Are they both coming from the same Prismic repository?
Are you trying to configure a menu for internal Prismic links or external URLs?

Thanks.

With this project I just have my local dev env and production which will be on Netlify. I've seen other meta fields apps just use a text field so I'm considering just using Key Text instead of a URL field. Another option i'm considering is just having the user enter /about, which is automatically formatted to http:///about by Prismic, and then just parsing out the http://.

What is the approach that is recommended by Prismic for Nuxt? I just followed the Nuxt slicemachine walk through tutorial where it has you create a menu type, but i dont see where it discussing relative links or templating said Custom Type.

You could strip out http:// like you suggested, but if your local dev and production environments are using the same Prismic repository there's no need to do that. The link resolver will find the correct document for you and create the link. Are you using 2 different repositories for this?

Using a key text field is an option, but there's no link validation. Using the link field will verify that a Prismic document exists and allows the Link Resolver to create links for different environments.

The tutorial offers code to template the menu here:

1 Like

Just to continue this conversation, this is a problem we have come up against today.

We want to link to a relative URL with query params, essentially linking to a filtered blog index page, so it would look like /blog?type=xxx

It's pretty horrible how the CMS automatically adds https:// to the start, and while the solution above to remove this does work, I agree it is gross! Especially to see https:///blog?type=xxx in the CMS. Doesn't present a good impression to the client.

Is this being looked into? Or is there a better workaround you guys would suggest?

1 Like

I agree - I wish Prismic would just remove the unnecessary https:// when adding a relative link - this will solve several feature tickets which are currently open in this forum

1 Like

Not sure which of the many related threads to contribute to the conversation on, so i'll pick this one.

For those of you that ended up here after getting your feet wet with Prismic, then in encountered this and thought "surely there has to be an elegant solution for this". There is not.

This is a big issue for our agency. In fact, it's the single biggest thing that causes us to abandon Prismic or use a different service initially.

By design, Prismic is never the router. Why should it dictate what a link can be? I understand that sometimes you want a link to represent a relationship to content that does live within Prismic and that's cool - especially when you are dealing with locales. But there is no reason to force links to be this way. As a rule with our clients, if 100% of the content doesn't live in Prismic, we recommend a different system. Because of the lack of relative paths in link fields. (Which is crazy because Prismic is awesome.) Occasionally you need to link your content to a section of your application that is outside of Prismic. Locking us into the choice between an absolute url and a resolved relationship means that, often, the most critical part of the application is left out or requires some messy workaround. We're tried it all; stripping the host, using key text fields, etc... It's all a complete mess to maintain and it's just plain ugly.

If the logic is that we can use a resolver to customize how a link is routed, then why can't the same be true for a relative path for locales? Which is definitely the less common scenario.

I have nothing constructive to offer for those of you that ended up here seeking a good solution. Like you, i'm especially disappointed in the lack of a fix for this considering how long this problem has been around. If you're like us and have to use or migrate to a different content system because of the lack of this feature, you can take your pick. We've tried every major alternative to Prismic. They all support a relative path in some form. But Prismic is our favorite and we can't use it most of the time. And that's a bummer.

2 Likes

We have an ecommerce app that uses querystrings to show custom views. It is not in Prismic, it will never be in Prismic. Adding stub documents is not an option. There is no option besides a key text field, or hacking off the aggressively unnecessary https:// added to the start of a link. It is so embarrassing, and makes me look stupid in front of clients.

The really cringe thing is that it is technically pointless, and really feels like a "nudge" to put content in Prismic, or like the Prismic team knows better about what my team should do with our own website. Prismic is just a part, a utility, please make it more useful instead of less.

This is a fantastic solution because https:/// is always invalid in a URL.

Hey Everyone,

I'm happy to tell you that you will be able to do relative links and will not be forced to append https:// in the new page builder, which is now in Alpha. :slight_smile: :tada:

Once the new builder is fully released, it will give us the flexibility to quickly iterate and add new features based on feedback from users like you.

You can read about the page builder in the link below.

BUT PLEASE BE WARNED:
The page builder is still in ALPHA, so there are some features that are not ready (PLEASE CHECK THE LIST).

Join the waitlist to try Prismic's new Page Builder to edit your website.

Thanks :slight_smile: