Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MooseSaid's avatar

How to make nuxt-link act as <a> if an .env variable is true?

I'm working with nuxt 2 and I need to treat some requests as if my website was MPA not SPA. So, nuxt-link built-in component by default is navigating the user to different routes without refreshing the page.

How can I make nuxt-link component to act as a normal <a> if there is specific .env variable is true?

0 likes
5 replies
MooseSaid's avatar

@Sinnbeck I just want nuxt-link component to render as a normal anchor tag if a specific nuxt.config.js variable is true. So it's the same as if a .env variable is true.

Sinnbeck's avatar

@MooseSaid but isn't the nuxt config in git? That means you cannot easily change it. Setting it in the env file allows you to do it from server to server

And in that case you can just use an if statement to return one or the other

1 like
MooseSaid's avatar

@Sinnbeck I have a lot of nuxt-links all over the project and I don't want to write an if statement for each of them to get what I need. A simple if statement would do but it would be much better if I can just manipulate the built-in nuxt-link component in the framework to behave the way I want it to. So I'm basically looking for a way to add code to the nuxt-link component to check for this flag or trigger that I will set and according to it, it renders the default nuxt-link or a normal <a> tag

Sinnbeck's avatar

@MooseSaid I doubt you can change the built in component. What I would do is to make my own component that takes exactly the same props, and just have that return either an a tag or a nuxt-link. Then you only need to maintain that one component

1 like

Please or to participate in this conversation.