import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
base: '/photography-page/',
})
import React from 'react'
import { createRoot } from 'react-dom/client'
import { BrowserRouter } from 'react-router-dom'
import App from './App'
...
const router = createBrowserRouter(
[
{ path: '/', element: <Loading /> },
{
path: '/app',
element: <App />,
children: [
{ index: true, element: <Narrative /> },
{ path: 'narrative', element: <Narrative /> },
{ path: 'videography', element: <Videography /> },
{ path: 'photography', element: <Photography /> },
{ path: 'contact', element: <Contact /> },
],
},
],
{ basename: '/photography-page' } // <<<<<<<<<<<<<<
)
name: Deploy Vite (React) to GitHub Pages
on:
push:
branches: [ main ]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install dependencies
run: |
if [ -f package-lock.json ]; then npm ci; else npm i; fi
- name: Build
run: npm run build
# SPA fallback so refresh/deep-links work on GH Pages
- name: Copy 404.html
run: cp dist/index.html dist/404.html
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: dist
deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
steps:
- name: Deploy to GitHub Pages
uses: actions/deploy-pages@v4
Deploy the backend first (Render/Railway/Fly/Heroku/Netlify Functions/etc.).
GitHub Pages is static-only and can’t run your Express server, so you need a live API URL before pointing your React app at it.
Then update your React app to use that API base and deploy to GitHub Pages.