Skip to content

Commit 87638c4

Browse files
committed
fix: support both Vercel and GitHub Pages routing
1 parent 3080244 commit 87638c4

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {HashRouter as Router, Route, Routes} from 'react-router-dom'
1+
import {HashRouter, BrowserRouter, Route, Routes} from 'react-router-dom'
22
import './App.css'
33
import NavBar from './components/NavBar'
44
import HomePage from './components/HomePage'
@@ -11,6 +11,9 @@ import PageTitle from './components/PageTitle'
1111
import './gh-fork-ribbon.css';
1212
import './styles/github-ribbon-fix.css';
1313

14+
// 根据环境选择路由器
15+
const Router = import.meta.env.VERCEL ? BrowserRouter : HashRouter;
16+
1417
const App = () => {
1518
return (
1619
<Router>

vercel.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"rewrites": [
3+
{
4+
"source": "/(.*)",
5+
"destination": "/index.html"
6+
}
7+
],
8+
"github": {
9+
"silent": true
10+
}
11+
}

vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ function challengesWatchPlugin(): Plugin {
222222

223223
// https://vite.dev/config/
224224
export default defineConfig({
225-
base: '/crawler-leetcode/',
225+
base: process.env.VERCEL ? '/' : '/crawler-leetcode/',
226226
plugins: [
227227
react(),
228228
virtualFileSystemPlugin({

0 commit comments

Comments
 (0)