|
1 | | -import { useEffect } from 'react'; |
2 | | -import { BrowserRouter, Routes, Route, useNavigate, useLocation } from 'react-router-dom'; |
| 1 | +import { BrowserRouter, Routes, Route } from 'react-router-dom'; |
3 | 2 | import { ConfigProvider, config } from '@/lib/config'; |
4 | 3 | import { BrandingEffects } from '@/components/branding-effects'; |
5 | 4 | import { NoticeProvider } from '@/components/notice-banner'; |
6 | 5 | import { Layout } from '@/components/layout'; |
7 | | -import { chatConversationPath, chatPath } from '@/lib/urls'; |
8 | 6 | import { ChatPage } from '@/pages/chat'; |
9 | 7 | import { CreatePage } from '@/pages/create'; |
10 | 8 | import { TerminalPage } from '@/pages/terminal'; |
11 | 9 |
|
12 | | -function HashRedirect() { |
13 | | - const navigate = useNavigate(); |
14 | | - const location = useLocation(); |
15 | | - |
16 | | - useEffect(() => { |
17 | | - const hash = window.location.hash; |
18 | | - if (!hash || hash === '#') return; |
19 | | - |
20 | | - // Convert legacy hash routes to path routes. |
21 | | - // #chat/name → /c/name |
22 | | - // #create → /create |
23 | | - // #terminal/name → /terminal/name |
24 | | - const match = hash.match(/^#(chat|terminal|create)(?:\/(.+?))?(?:\/([^/]+))?$/); |
25 | | - if (match) { |
26 | | - const route = match[1]; |
27 | | - const param = match[2] || ''; |
28 | | - const subParam = match[3] || ''; |
29 | | - const path = route === 'chat' |
30 | | - ? subParam |
31 | | - ? chatConversationPath(param, subParam) |
32 | | - : chatPath(param) |
33 | | - : subParam |
34 | | - ? `/${route}/${param}/${subParam}` |
35 | | - : param |
36 | | - ? `/${route}/${param}` |
37 | | - : `/${route}`; |
38 | | - window.history.replaceState(null, '', window.location.pathname + window.location.search); |
39 | | - navigate(path, { replace: true }); |
40 | | - } |
41 | | - }, [location, navigate]); |
42 | | - |
43 | | - return null; |
44 | | -} |
45 | | - |
46 | 10 | export function App() { |
47 | 11 | return ( |
48 | 12 | <BrowserRouter> |
49 | 13 | <ConfigProvider value={config}> |
50 | 14 | <BrandingEffects /> |
51 | 15 | <NoticeProvider> |
52 | | - <HashRedirect /> |
53 | 16 | <Routes> |
54 | 17 | <Route element={<Layout />}> |
55 | 18 | <Route index element={<ChatPage />} /> |
56 | 19 | <Route path="create" element={<CreatePage />} /> |
57 | 20 | <Route path="terminal/:name" element={<TerminalPage />} /> |
58 | 21 | <Route path="c/:name?" element={<ChatPage />} /> |
59 | 22 | <Route path="c/:name/:conversationId" element={<ChatPage />} /> |
60 | | - <Route path="chat/:name?" element={<ChatPage />} /> |
61 | | - <Route path="chat/:name/:conversationId" element={<ChatPage />} /> |
62 | 23 | </Route> |
63 | 24 | </Routes> |
64 | 25 | </NoticeProvider> |
|
0 commit comments