Next.js Discord

Discord Forum

Is it possible to prevent the base url being appended to the href for a next/link?

Unanswered
Polar bear posted this in #help-forum
Open in Discord
Polar bearOP
We currently have multiple next apps hosted as different projects but living under the same url through the use of cloudfront as micro-frontends. Each individual app has a different base url set to support this architecture.
However, we are coming across an issue where when we use next/link, the href gets turned into https://www.website.com/(appbaseurl)/page from a normal expected href of https://www.website.com/page.
We just want the next link to not append the base url to the href. Is this possible at all?

Thanks

6 Replies

Boreal Owl
Taking over from @Polar bear as they're off this issue now, it's a bit of a pain to explain unfortunately.

We have Website#1 and Website#2, and a SharedNavigation component as an NPM package, we pass the '@next/link' component from each website down into the SharedNavigation component.

Website#1 has a base path of '/'
Website#2 has a base path of '/blogapp'

Website#2 has sub routes for '/featured', etc

Currently with Next link the url generated is https://www.website.com/blogapp/featured

But we'd like it to be https://www.website.com/featured

As for our <Link/> component, we're effectively writing a wrapper around the '@next/link' component in our SharedNavigation package.
Polar bearOP
Anyone have any idea how this could be solved?
Asian black bear
You do not use <Link> to link between "multiple next apps hosted as different projects"
I do not think this would be normal or expected by anyone:
https://www.website.com/(appbaseurl)/page from a normal expected href of https://www.website.com/page.