Skip to content

Commit

Permalink
chore: path
Browse files Browse the repository at this point in the history
  • Loading branch information
lencx committed Nov 13, 2023
1 parent 3c638c6 commit c9a7437
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
12 changes: 12 additions & 0 deletions 404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Not Found</title>
<script>
window.location.replace('/index.html' + '?path=' + window.location.pathname);
</script>
</head>
<body>
<h1>Page Not Found</h1>
</body>
</html>
11 changes: 11 additions & 0 deletions src/layouts/base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ export default function BaseLayout() {
const [isDark, setDark] = useState(false);
const navigate = useNavigate();

useEffect(() => {
if (window.location.search) {
const params = new URLSearchParams(window.location.search);
const path = params.get('path');
if (path) {
navigate(`/${path}`);
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [window.location.search])

useEffect(() => {
const theme = localStorage.getItem('theme');
const isDark2 = theme === 'dracula';
Expand Down
9 changes: 2 additions & 7 deletions src/views/GPTDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useLayoutEffect, useMemo } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { useMemo } from 'react';
import { useParams } from 'react-router-dom';
import dayjs from 'dayjs';

import { gptLink } from '@/utils';
Expand All @@ -11,11 +11,6 @@ import data from '@@/gpthub.json';

export default function GPTs() {
const params = useParams();
const navigate = useNavigate();

useLayoutEffect(() => {
navigate(`/gpts/${params?.id}`)
}, [params?.id, navigate])

const gptInfo = useMemo(() => {
return data?.gpts?.find((item) => item.id === params?.id);
Expand Down
9 changes: 9 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ import { defineConfig, splitVendorChunkPlugin } from 'vite';
// import { VitePWA } from 'vite-plugin-pwa';
import react from '@vitejs/plugin-react-swc';
import tsconfigPaths from 'vite-tsconfig-paths';
import { resolve } from 'path';

// https://vitejs.dev/config/
export default defineConfig({
base: '/',
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
404: resolve(__dirname, '404.html'),
},
},
},
plugins: [
tsconfigPaths(),
react(),
Expand Down

0 comments on commit c9a7437

Please sign in to comment.