11import { Suspense , lazy } from "react" ;
2- import { Routes , Route } from "react-router" ;
2+ import { Navigate , Routes , Route , useLocation , useParams } from "react-router" ;
33
44import LoadingPage from "@/components/LoadingPage" ;
55import NotFound from "@/components/NotFound" ;
6+ import {
7+ bookmarksPath ,
8+ contentPath ,
9+ peoplePath ,
10+ personPath ,
11+ schedulePath ,
12+ } from "@/lib/utils/routes" ;
613
714const SplashRoute = lazy ( ( ) =>
815 import ( "../features/splash/Splash" ) . then ( ( module ) => ( {
@@ -40,9 +47,9 @@ const BookmarksRoute = lazy(() =>
4047 } ) ) ,
4148) ;
4249
43- const EventRoute = lazy ( ( ) =>
44- import ( "../features/event/Event " ) . then ( ( module ) => ( {
45- default : module . Event ,
50+ const ContentRoute = lazy ( ( ) =>
51+ import ( "../features/content/Content " ) . then ( ( module ) => ( {
52+ default : module . ContentDetailPage ,
4653 } ) ) ,
4754) ;
4855
@@ -58,6 +65,57 @@ const PersonRoute = lazy(() =>
5865 } ) ) ,
5966) ;
6067
68+ function parseLegacyId ( value : string | null ) : number | null {
69+ if ( ! value || ! / ^ \d + $ / . test ( value ) ) return null ;
70+ return Number ( value ) ;
71+ }
72+
73+ function LegacyRedirect ( ) {
74+ const { pathname, search } = useLocation ( ) ;
75+ const params = new URLSearchParams ( search ) ;
76+ const confCode = params . get ( "conf" ) ?? params . get ( "conference" ) ;
77+ const contentId = parseLegacyId ( params . get ( "event" ) ?? params . get ( "content" ) ?? params . get ( "id" ) ) ;
78+ const personId = parseLegacyId ( params . get ( "person" ) ?? params . get ( "id" ) ) ;
79+
80+ if ( ! confCode ) return < NotFound /> ;
81+
82+ if (
83+ pathname === "/event" ||
84+ pathname === "/event/" ||
85+ pathname === "/content" ||
86+ pathname === "/content/"
87+ ) {
88+ return contentId ? < Navigate replace to = { contentPath ( confCode , contentId ) } /> : < NotFound /> ;
89+ }
90+
91+ if ( pathname === "/schedule" ) {
92+ return < Navigate replace to = { schedulePath ( confCode ) } /> ;
93+ }
94+
95+ if ( pathname === "/bookmarks" ) {
96+ return < Navigate replace to = { bookmarksPath ( confCode ) } /> ;
97+ }
98+
99+ if ( pathname === "/people" || pathname === "/people/" ) {
100+ return (
101+ < Navigate replace to = { personId ? personPath ( confCode , personId ) : peoplePath ( confCode ) } />
102+ ) ;
103+ }
104+
105+ if ( pathname === "/person" ) {
106+ return personId ? < Navigate replace to = { personPath ( confCode , personId ) } /> : < NotFound /> ;
107+ }
108+
109+ return < NotFound /> ;
110+ }
111+
112+ function LegacyContentRedirect ( ) {
113+ const { confCode, contentId } = useParams ( ) ;
114+ const parsedContentId = contentId && / ^ \d + $ / . test ( contentId ) ? Number ( contentId ) : null ;
115+ if ( ! confCode || ! parsedContentId ) return < NotFound /> ;
116+ return < Navigate replace to = { contentPath ( confCode , parsedContentId ) } /> ;
117+ }
118+
61119export default function AppRouter ( ) {
62120 return (
63121 < Routes >
@@ -77,46 +135,63 @@ export default function AppRouter() {
77135 </ Suspense >
78136 }
79137 />
138+ < Route path = "/schedule" element = { < LegacyRedirect /> } />
139+ < Route path = "/bookmarks" element = { < LegacyRedirect /> } />
140+ < Route path = "/people" element = { < LegacyRedirect /> } />
141+ < Route path = "/people/" element = { < LegacyRedirect /> } />
142+ < Route path = "/person" element = { < LegacyRedirect /> } />
143+ < Route path = "/event" element = { < LegacyRedirect /> } />
144+ < Route path = "/content" element = { < LegacyRedirect /> } />
145+ < Route path = "/content/" element = { < LegacyRedirect /> } />
146+ < Route
147+ path = "/:confCode"
148+ element = {
149+ < Suspense fallback = { < LoadingPage message = "Loading schedule..." /> } >
150+ < ScheduleRoute />
151+ </ Suspense >
152+ }
153+ />
80154 < Route
81- path = "/schedule"
155+ path = "/:confCode/ schedule"
82156 element = {
83157 < Suspense fallback = { < LoadingPage message = "Loading schedule..." /> } >
84158 < ScheduleRoute />
85159 </ Suspense >
86160 }
87161 />
88162 < Route
89- path = "/bookmarks"
163+ path = "/:confCode/ bookmarks"
90164 element = {
91165 < Suspense fallback = { < LoadingPage message = "Loading bookmarks..." /> } >
92166 < BookmarksRoute />
93167 </ Suspense >
94168 }
95169 />
96170 < Route
97- path = "/people"
171+ path = "/:confCode/ people"
98172 element = {
99173 < Suspense fallback = { < LoadingPage message = "Loading people..." /> } >
100174 < PeopleRoute />
101175 </ Suspense >
102176 }
103177 />
104178 < Route
105- path = "/person "
179+ path = "/:confCode/people/:personId "
106180 element = {
107181 < Suspense fallback = { < LoadingPage message = "Loading person..." /> } >
108182 < PersonRoute />
109183 </ Suspense >
110184 }
111185 />
112186 < Route
113- path = "/event "
187+ path = "/:confCode/content/:contentId "
114188 element = {
115- < Suspense fallback = { < LoadingPage message = "Loading event ..." /> } >
116- < EventRoute />
189+ < Suspense fallback = { < LoadingPage message = "Loading content ..." /> } >
190+ < ContentRoute />
117191 </ Suspense >
118192 }
119193 />
194+ < Route path = "/:confCode/event/:contentId" element = { < LegacyContentRedirect /> } />
120195 < Route
121196 path = "/about"
122197 element = {
0 commit comments