Skip to content

Commit 2c7b9b1

Browse files
committed
Update deployment base path to use package name from package.json and add 404 fallback for SPA routes
1 parent fd2d853 commit 2c7b9b1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

.github/workflows/static.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ jobs:
6161
BASE_PATH: ${{ steps.vars.outputs.subpath }}
6262
run: |
6363
# Compute a single deploy base that always ends with a trailing slash
64-
# Use repository name as base (strip organization and .git if present)
65-
REPO_NAME=$(basename -s .git "${GITHUB_REPOSITORY}")
64+
# Use package name from package.json as base so built assets match paths
65+
REPO_NAME=$(node -e "console.log(require('./package.json').name)")
6666
if [ -n "$BASE_PATH" ]; then
6767
DEPLOY_BASE="/${REPO_NAME}/${BASE_PATH}/"
6868
else
@@ -75,6 +75,8 @@ jobs:
7575
echo "Building with DEPLOY_BASE=$DEPLOY_BASE"
7676
7777
npm run build
78+
# Ensure SPA routes work on GitHub Pages by providing a 404 fallback
79+
if [ -f dist/index.html ]; then cp dist/index.html dist/404.html || true; fi
7880
7981
- name: Setup Pages
8082
uses: actions/configure-pages@v5
@@ -131,8 +133,8 @@ jobs:
131133
BASE_PATH: ${{ steps.vars.outputs.subpath }}
132134
run: |
133135
# Compute a single deploy base that always ends with a trailing slash
134-
# Use repository name as base (strip organization and .git if present)
135-
REPO_NAME=$(basename -s .git "${GITHUB_REPOSITORY}")
136+
# Use package name from package.json as base so built assets match paths
137+
REPO_NAME=$(node -e "console.log(require('./package.json').name)")
136138
if [ -n "$BASE_PATH" ]; then
137139
DEPLOY_BASE="/${REPO_NAME}/${BASE_PATH}/"
138140
else
@@ -145,6 +147,8 @@ jobs:
145147
echo "Building with DEPLOY_BASE=$DEPLOY_BASE"
146148
147149
npm run build
150+
# Ensure SPA routes work on GitHub Pages by providing a 404 fallback
151+
if [ -f dist/index.html ]; then cp dist/index.html dist/404.html || true; fi
148152
149153
- name: Setup Pages
150154
uses: actions/configure-pages@v5

0 commit comments

Comments
 (0)