Skip to content

Commit 4aa2120

Browse files
committed
fix: normalize BASE_URL trailing slash for correct production URLs
trailingSlash: "never" strips the trailing slash from BASE_URL, causing all manual path concatenations to produce broken URLs like /ocyncgetting-started. Normalize base to always end with "/" in all components.
1 parent b14c6a8 commit 4aa2120

4 files changed

Lines changed: 7 additions & 4 deletions

File tree

docs/src/layouts/BaseLayout.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface Props {
1010
import "../styles/global.css";
1111
import { ClientRouter } from "astro:transitions";
1212
13-
const base = import.meta.env.BASE_URL;
13+
const base = import.meta.env.BASE_URL.endsWith("/") ? import.meta.env.BASE_URL : `${import.meta.env.BASE_URL}/`;
1414
1515
const {
1616
title,

docs/src/layouts/DocLayout.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ interface Props {
99
1010
const { title, description, headings = [] } = Astro.props;
1111
const currentPath = Astro.url.pathname.replace(/\/$/, '');
12-
const base = import.meta.env.BASE_URL;
12+
const rawBase = import.meta.env.BASE_URL;
13+
const base = rawBase.endsWith("/") ? rawBase : `${rawBase}/`;
1314
1415
// Section definitions: each maps to a header nav tab
1516
const navSections = {

docs/src/pages/404.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
import BaseLayout from "../layouts/BaseLayout.astro";
33
4-
const base = import.meta.env.BASE_URL;
4+
const rawBase = import.meta.env.BASE_URL;
5+
const base = rawBase.endsWith("/") ? rawBase : `${rawBase}/`;
56
---
67

78
<BaseLayout title="Page not found" description="The page you are looking for does not exist.">

docs/src/pages/index.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
import BaseLayout from "../layouts/BaseLayout.astro";
33
4-
const base = import.meta.env.BASE_URL;
4+
const rawBase = import.meta.env.BASE_URL;
5+
const base = rawBase.endsWith("/") ? rawBase : `${rawBase}/`;
56
67
const jsonLd = {
78
"@context": "https://schema.org",

0 commit comments

Comments
 (0)