diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9420eba..3263113 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,6 +4,9 @@ on: push: branches: - main + pull_request: + branches: + - main jobs: build: @@ -20,8 +23,14 @@ jobs: - name: Install dependencies run: npm ci --legacy-peer-deps + - name: Set Base URL + id: set_base_url + run: echo "base_url=/${{ github.event.repository.name }}/" >> $GITHUB_OUTPUT + - name: Build project run: npm run build + env: + VITE_BASE_URL: ${{ steps.set_base_url.outputs.base_url }} - name: Upload static files as artifact id: deployment diff --git a/public/404.html b/public/404.html index db6ca75..1773d5e 100644 --- a/public/404.html +++ b/public/404.html @@ -22,7 +22,7 @@ // https://username.github.io/repo-name/one/two?a=b&c=d#qwe becomes // https://username.github.io/repo-name/?/one/two&a=b~and~c=d#qwe // Otherwise, leave pathSegmentsToKeep as 0. - var pathSegmentsToKeep = 0; + var pathSegmentsToKeep = 1; var l = window.location; l.replace( diff --git a/src/index.jsx b/src/index.jsx index 8fb073a..c1d7472 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -1,6 +1,7 @@ import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import { Routes } from '@generouted/react-router' +import { createBrowserRouter, RouterProvider } from 'react-router-dom' +import { routes } from '@generouted/react-router' import { ThemeProvider, BaseStyles } from '@primer/react' import './reset.css' @@ -8,6 +9,7 @@ import './globals.css' import ColorModeSwitcher from './components/ColorModeSwitcher' +const router = createBrowserRouter(routes, { basename: import.meta.env.VITE_BASE_URL }) const rootElement = document.getElementById('root') const root = createRoot(rootElement) @@ -16,7 +18,7 @@ root.render( - + diff --git a/vite.config.js b/vite.config.js index bdde880..e1c0bca 100644 --- a/vite.config.js +++ b/vite.config.js @@ -7,6 +7,7 @@ import browsers from '@github/browserslist-config' import { globSync } from 'glob' export default defineConfig({ + base: process.env.VITE_BASE_URL || '/', plugins: [react(), generouted()], server: { port: 1234 }, css: {