Spaces:
Running
Running
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>
12234520 unmodified lines2627282930313229303132333435363764 unmodified lines102103104105106107108109import { useEffect } from 'react';import { BrowserRouter, Routes, Route, useLocation, useNavigate } from 'react-router-dom';import { BrowserRouter, Routes, Route, Navigate, useLocation, useNavigate } from 'react-router-dom';import { ThemeProvider, CssBaseline } from '@mui/material';import theme from './theme/theme';import { AppsProvider } from './context/AppsContext';20 unmodified lines
useEffect(() => { const hash = window.location.hash; // Match hash routes like #/apps, #/download, etc. if (hash && hash.startsWith('#/')) { const path = hash.slice(1); // Remove the # to get /apps window.location.hash = ''; // Clean up the hash // Match hash routes like #/apps, #/download, #apps, #download, etc. if (hash && hash.length > 1) { // Support both #/apps and #apps formats const path = hash.startsWith('#/') ? hash.slice(1) : `/${hash.slice(1)}`; // Use replaceState to cleanly remove hash without triggering navigation window.history.replaceState(null, '', window.location.pathname); navigate(path, { replace: true }); } }, [navigate]);64 unmodified lines <Route path="https://huggingface.co/docs/reachy_mini/troubleshooting" element={<FAQ />} /> <Route path="/apps" element={<Apps />} /> <Route path="/buy" element={<Buy />} /> {/* Catch-all: redirect unknown routes to home */} <Route path="*" element={<Navigate to="/" replace />} /> </Routes> </BrowserRouter> </AppsProvider>src/App.jsx+9-5