Skip to content

Commit d72b417

Browse files
committed
fix: Directly opening routed URL shows 404 page
1 parent e320436 commit d72b417

3 files changed

Lines changed: 9 additions & 31 deletions

File tree

client/404.html

Lines changed: 0 additions & 22 deletions
This file was deleted.

server/vite.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import express, { type Express } from "express";
22
import fs from "fs";
3+
import { type Server } from "http";
4+
import { nanoid } from "nanoid";
35
import path from "path";
46
import { fileURLToPath } from "url";
5-
import { createServer as createViteServer, createLogger } from "vite";
6-
import { type Server } from "http";
7+
import { createLogger, createServer as createViteServer } from "vite";
78
import viteConfig from "../vite.config";
8-
import { nanoid } from "nanoid";
99

1010
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1111

vite.config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { defineConfig } from "vite";
1+
import runtimeErrorOverlay from "@replit/vite-plugin-runtime-error-modal";
22
import react from "@vitejs/plugin-react";
3+
import fs from 'fs';
34
import path from "path";
45
import { fileURLToPath } from "url";
5-
import runtimeErrorOverlay from "@replit/vite-plugin-runtime-error-modal";
6-
import fs from 'fs';
6+
import { defineConfig } from "vite";
77

88
const __dirname = path.dirname(fileURLToPath(import.meta.url));
99

10-
// Plugin to copy 404.html for GitHub Pages SPA routing
10+
// Plugin to copy index.html as 404.html for GitHub Pages SPA routing
1111
function copy404Plugin() {
1212
return {
1313
name: 'copy-404',
1414
closeBundle() {
15-
const src = path.resolve(__dirname, 'client', '404.html');
15+
const src = path.resolve(__dirname, 'dist', 'public', 'index.html');
1616
const dest = path.resolve(__dirname, 'dist', 'public', '404.html');
1717
if (fs.existsSync(src)) {
1818
fs.copyFileSync(src, dest);
19-
console.log('✓ Copied 404.html for GitHub Pages SPA routing');
19+
console.log('✓ Copied index.html as 404.html for GitHub Pages SPA routing');
2020
}
2121
}
2222
};

0 commit comments

Comments
 (0)