40 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-06-25 13:47:07 +08:00
import { Route, Routes, useLocation } from 'react-router-dom'
2022-05-29 17:53:27 +08:00
import Search from '@/web/pages/Search'
import Settings from '@/web/pages/Settings'
import { AnimatePresence } from 'framer-motion'
import React, { ReactNode, Suspense } from 'react'
const My = React.lazy(() => import('@/web/pages/New/My'))
const Discover = React.lazy(() => import('@/web/pages/New/Discover'))
2022-06-14 23:23:34 +08:00
const Browse = React.lazy(() => import('@/web/pages/New/Browse'))
2022-05-29 17:53:27 +08:00
const Album = React.lazy(() => import('@/web/pages/New/Album'))
2022-06-06 01:00:25 +08:00
const Playlist = React.lazy(() => import('@/web/pages/New/Playlist'))
2022-06-25 13:47:07 +08:00
const Artist = React.lazy(() => import('@/web/pages/New/Artist'))
2022-05-29 17:53:27 +08:00
2022-06-25 13:47:07 +08:00
const lazy = (component: ReactNode) => {
return <Suspense>{component}</Suspense>
2022-05-29 17:53:27 +08:00
}
const Router = () => {
const location = useLocation()
return (
<AnimatePresence exitBeforeEnter>
<Routes location={location} key={location.pathname}>
<Route path='/' element={lazy(<My />)} />
<Route path='/discover' element={lazy(<Discover />)} />
2022-06-14 23:23:34 +08:00
<Route path='/browse' element={lazy(<Browse />)} />
2022-05-29 17:53:27 +08:00
<Route path='/album/:id' element={lazy(<Album />)} />
2022-06-06 01:00:25 +08:00
<Route path='/playlist/:id' element={lazy(<Playlist />)} />
2022-06-25 13:47:07 +08:00
<Route path='/artist/:id' element={lazy(<Artist />)} />
<Route path='/settings' element={lazy(<Settings />)} />
<Route path='/search/:keywords' element={lazy(<Search />)}>
<Route path=':type' element={lazy(<Search />)} />
</Route>
2022-05-29 17:53:27 +08:00
</Routes>
</AnimatePresence>
)
}
export default Router