11import { lazy , Suspense , Component } from 'react' ;
2- import { Routes , Route , Navigate } from 'react-router-dom' ;
2+ import { Routes , Route , Navigate , useLocation } from 'react-router-dom' ;
33import Layout from './layouts/Layout' ;
44import LanguageSync from './components/LanguageSync' ;
55import PageLoader from './components/PageLoader' ;
@@ -55,16 +55,18 @@ function LazyPage({ children }) {
5555 ) ;
5656}
5757
58- function RootRedirect ( ) {
58+ function LegacyRedirect ( ) {
59+ const location = useLocation ( ) ;
5960 const lang = localStorage . getItem ( 'pycon-lang' ) || 'en' ;
60- return < Navigate to = { `/${ lang } ` } replace /> ;
61+ const path = location . pathname === '/' ? '' : location . pathname ;
62+ return < Navigate to = { `/${ lang } ${ path } ${ location . search } ${ location . hash } ` } replace /> ;
6163}
6264
6365function App ( ) {
6466 return (
6567 < Routes >
6668 { /* Root redirect to default language */ }
67- < Route index element = { < RootRedirect /> } />
69+ < Route index element = { < LegacyRedirect /> } />
6870
6971 { /* Language-prefixed routes */ }
7072 < Route path = "/:lang" element = { < LanguageSync > < Layout /> </ LanguageSync > } >
@@ -79,11 +81,11 @@ function App() {
7981 < Route path = "health-safety" element = { < LazyPage > < HealthSafety /> </ LazyPage > } />
8082 < Route path = "code-of-conduct" element = { < LazyPage > < CodeOfConduct /> </ LazyPage > } />
8183 < Route path = "ubucon" element = { < LazyPage > < UbuCon /> </ LazyPage > } />
82- < Route path = "*" element = { < RootRedirect /> } />
84+ < Route path = "*" element = { < LegacyRedirect /> } />
8385 </ Route >
8486
8587 { /* Catch-all */ }
86- < Route path = "*" element = { < RootRedirect /> } />
88+ < Route path = "*" element = { < LegacyRedirect /> } />
8789 </ Routes >
8890 ) ;
8991}
0 commit comments