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>
1234520 unmodified lines2627282930313233343564 unmodified lines100101102103104105import { useEffect } from 'react';import { BrowserRouter, Routes, Route, useLocation, useNavigate } from 'react-router-dom';import { ThemeProvider, CssBaseline } from '@mui/material';import theme from './theme/theme';import { AppsProvider } from './context/AppsContext';20 unmodified linesuseEffect(() => {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 /appswindow.location.hash = ''; // Clean up the hashnavigate(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 />} /></Routes></BrowserRouter></AppsProvider>1234520 unmodified lines26272829303132333435363764 unmodified lines102103104105106107108109import { useEffect } from 'react';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 linesuseEffect(() => {const hash = window.location.hash;// Match hash routes like #/apps, #/download, #apps, #download, etc.if (hash && hash.length > 1) {// Support both #/apps and #apps formatsconst path = hash.startsWith('#/') ? hash.slice(1) : `/${hash.slice(1)}`;// Use replaceState to cleanly remove hash without triggering navigationwindow.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