Skip to content

Commit bbe1c21

Browse files
committed
fix(website): stop double-prefixing basePath on internal links
Next.js's <Link> already prepends `basePath` to root-relative hrefs. The `link()` helper was *also* prepending it, producing `/self-driving-agents/self-driving-agents/<path>` on every internal nav. Strip the prefix from `link()` (now just normalises to leading-slash) and keep `asset()` as the only place that adds basePath — used for plain <img src>, favicon, and other raw HTML attributes that Next does not auto-prefix.
1 parent 0ca6646 commit bbe1c21

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

website/src/lib/link.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
/**
2-
* Build an internal link with the configured base path.
2+
* Build an href for internal navigation through `<Link>`.
33
*
4-
* Next.js `<Link href="/foo">` does NOT prepend basePath when href starts
5-
* with a slash AND we're using `output: 'export'`. To keep static asset
6-
* paths and anchor hrefs consistent we apply the base manually.
4+
* Next.js's `<Link>` already prepends the configured `basePath` to root-
5+
* relative hrefs, so this helper must NOT add it again — otherwise we get
6+
* `/<base>/<base>/path`. The function exists only to normalise inputs to a
7+
* leading-slash form and to keep call sites uniform.
78
*/
8-
const BASE = process.env.NEXT_PUBLIC_BASE_PATH || '';
9-
109
export function link(path: string): string {
11-
if (!path.startsWith('/')) return `${BASE}/${path}`;
12-
return `${BASE}${path}`;
10+
return path.startsWith('/') ? path : `/${path}`;
1311
}
1412

1513
/**
16-
* Build an asset URL under /public — used for logos and favicons since
17-
* `<img src>` does not pick up basePath automatically with `output: 'export'`.
14+
* Build a URL for static assets under /public.
15+
*
16+
* Plain `<img src>`, `<link rel="icon">`, and other raw HTML attributes do
17+
* NOT get basePath prepended by Next.js. We have to do it ourselves.
1818
*/
19+
const BASE = process.env.NEXT_PUBLIC_BASE_PATH || '';
20+
1921
export function asset(path: string): string {
20-
return link(path.startsWith('/') ? path : `/${path}`);
22+
const p = path.startsWith('/') ? path : `/${path}`;
23+
return `${BASE}${p}`;
2124
}

0 commit comments

Comments
 (0)