Skip to content

Commit 00ea2d5

Browse files
authored
Publish to pages - fixing base path (#3)
* adding workflows and static site config * whoops path issue * adding base path while we don't have a custom domain * fixing index redirect for static export * fixing dynamic redirect for static export
1 parent 1234e00 commit 00ea2d5

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

.github/workflows/deploy.docs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
node-version: "24"
4848

4949
- name: Setup Pages
50+
id: setup_pages
5051
uses: actions/configure-pages@v5
5152

5253
- name: Restore cache
@@ -63,6 +64,8 @@ jobs:
6364

6465
- name: Build with Next.js
6566
run: ${{ steps.detect-package-manager.outputs.runner }} next build
67+
env:
68+
PAGES_BASE_PATH: ${{ steps.setup_pages.outputs.base_path }}
6669

6770
- name: Copy built files to docs
6871
run: |

app/page.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
import { RedirectType, redirect } from "next/navigation";
1+
"use client";
22

3-
export default function Home() {
4-
redirect("v1", RedirectType.replace);
5-
}
3+
import dynamic from "next/dynamic";
4+
5+
// Can't use @next/navigation redirect() in static exports
6+
// So instead we use Browser `location` API, but we have to prevent the page from pre-rendering
7+
8+
// Client Component that does the redirect
9+
const RedirectComponent = () => {
10+
location.replace("v1");
11+
return null;
12+
};
13+
14+
// export the Component dynamically, with SSR (pre-rendering) disabled, as the Page
15+
export default dynamic(() => Promise.resolve(RedirectComponent), {
16+
ssr: false,
17+
});

next.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const withNextra = nextra({
88

99
const nextConfig: NextConfig = {
1010
output: "export",
11+
basePath: process.env.PAGES_BASE_PATH, // TODO: fix when custom domain mapping
1112
images: {
1213
unoptimized: true, // mandatory, otherwise won't export
1314
},

0 commit comments

Comments
 (0)