tfrere HF Staff Cursor commited on
Commit
61eecf2
·
1 Parent(s): 800eea1

fix: add catch-all route and improve hash redirect handling

Browse files

- Add catch-all route (*) that redirects to home for unknown paths
- Support both #/apps and #apps hash formats from HF parent
- Use history.replaceState instead of window.location.hash for cleaner
hash cleanup without potential side effects

Co-authored-by: Cursor <cursoragent@cursor.com>

Files changed (1) hide show
  1. src/App.jsx +9 -5
src/App.jsx CHANGED
@@ -1,5 +1,5 @@
1
  import { useEffect } from 'react';
2
- import { BrowserRouter, Routes, Route, useLocation, useNavigate } from 'react-router-dom';
3
  import { ThemeProvider, CssBaseline } from '@mui/material';
4
  import theme from './theme/theme';
5
  import { AppsProvider } from './context/AppsContext';
@@ -26,10 +26,12 @@ function HashRedirect() {
26
 
27
  useEffect(() => {
28
  const hash = window.location.hash;
29
- // Match hash routes like #/apps, #/download, etc.
30
- if (hash && hash.startsWith('#/')) {
31
- const path = hash.slice(1); // Remove the # to get /apps
32
- window.location.hash = ''; // Clean up the hash
 
 
33
  navigate(path, { replace: true });
34
  }
35
  }, [navigate]);
@@ -100,6 +102,8 @@ export default function App() {
100
  <Route path="https://huggingface.co/docs/reachy_mini/troubleshooting" element={<FAQ />} />
101
  <Route path="/apps" element={<Apps />} />
102
  <Route path="/buy" element={<Buy />} />
 
 
103
  </Routes>
104
  </BrowserRouter>
105
  </AppsProvider>
 
1
  import { useEffect } from 'react';
2
+ import { BrowserRouter, Routes, Route, Navigate, useLocation, useNavigate } from 'react-router-dom';
3
  import { ThemeProvider, CssBaseline } from '@mui/material';
4
  import theme from './theme/theme';
5
  import { AppsProvider } from './context/AppsContext';
 
26
 
27
  useEffect(() => {
28
  const hash = window.location.hash;
29
+ // Match hash routes like #/apps, #/download, #apps, #download, etc.
30
+ if (hash && hash.length > 1) {
31
+ // Support both #/apps and #apps formats
32
+ const path = hash.startsWith('#/') ? hash.slice(1) : `/${hash.slice(1)}`;
33
+ // Use replaceState to cleanly remove hash without triggering navigation
34
+ window.history.replaceState(null, '', window.location.pathname);
35
  navigate(path, { replace: true });
36
  }
37
  }, [navigate]);
 
102
  <Route path="https://huggingface.co/docs/reachy_mini/troubleshooting" element={<FAQ />} />
103
  <Route path="/apps" element={<Apps />} />
104
  <Route path="/buy" element={<Buy />} />
105
+ {/* Catch-all: redirect unknown routes to home */}
106
+ <Route path="*" element={<Navigate to="/" replace />} />
107
  </Routes>
108
  </BrowserRouter>
109
  </AppsProvider>