Skip to content

Commit bd94379

Browse files
committed
feat: fuck router
1 parent ab8cee4 commit bd94379

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/App.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ const StyledLink = styled(Link)(({ theme }) => ({
7272
function NavLinks() {
7373
const location = useLocation();
7474

75+
// 修复路由匹配逻辑,使用hash路由的pathname
7576
const isActive = (path: string) => {
76-
if (path === '/') return location.pathname === path;
77-
return location.pathname.startsWith(path);
77+
const hashPath = location.hash.replace('#', '');
78+
if (path === '/') return hashPath === '/';
79+
return hashPath.startsWith(path);
7880
};
7981

8082
return (
@@ -94,7 +96,7 @@ function NavLinks() {
9496

9597
function MainApp() {
9698
return (
97-
<Router basename="/ai-coding-prompt-builder/">
99+
<Router basename="/">
98100
<AppBar
99101
position="static"
100102
color="default"
@@ -117,8 +119,6 @@ function MainApp() {
117119
<Route path="/" element={<Home />} />
118120
<Route path="/prompt" element={<PromptTemplate />} />
119121
<Route path="/about" element={<About />} />
120-
{/* 添加404回退路由 */}
121-
<Route path="*" element={<Home />} />
122122
</Routes>
123123

124124
<footer style={{

vite.config.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { defineConfig } from 'vite'
22
import react from '@vitejs/plugin-react'
33

4-
// https://vite.dev/config/
54
export default defineConfig({
6-
base: '/ai-coding-prompt-builder/',
7-
plugins: [react()],
8-
})
5+
plugins: [react()],
6+
base: '/ai-coding-prompt-builder/', // 保持base配置不变
7+
build: {
8+
outDir: 'dist',
9+
assetsDir: 'assets'
10+
}
11+
})

0 commit comments

Comments
 (0)