Next.js Discord

Discord Forum

Disable basePath when using <Link>

Unanswered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
is it possible to disable the addition of the basePath when using <Link>?
My problem is that if I want to dynamically link to the deployed path without the basePath <Link> does not seem to support it.

basepath /test
<Link href="myTest" >
Will result int /test/myTest

According to the docs, the is no flag to be passed into Link to ignore the basepath.

Current workaround:
Native <a> Tag since it ignores the basePath

7 Replies

Beveren
Having the same issue, is there any workaround available for this?
Can u show the code and the file path?
Beveren
same as the example above
<Link href="myTest" > Will result int /test/myTest
so we need basePath for our aws cloudfront because we have 2 nextjs apps, basepath helps cloudfront to direct every request from the two nextjs apps BUT we dont need the basepath in the url.
Beveren
sorry, we are using APP router
Beveren
I tried rewrites, and it sure hides the basepath, but once i do navigation such as <Link> or router.push() it auto adds the basepath.
u can use the full url
"use client";

import Link from "next/link";

export default function LinkRouter({
  href,
  children,
}: {
  href: string;
  children: React.ReactNode;
}) {
  return <Link href={`http://localhost:3000/${href}`}>{children}</Link>;
}