first commit
This commit is contained in:
29
src/routes/__root.tsx
Normal file
29
src/routes/__root.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { useEffect } from 'react'
|
||||
import { createRootRoute, Outlet, useLocation } from '@tanstack/react-router'
|
||||
import Header from '../components/layout/Header'
|
||||
import Footer from '../components/layout/Footer'
|
||||
import ScrollToTop from '../components/layout/ScrollToTop'
|
||||
|
||||
export const Route = createRootRoute({
|
||||
component: RootLayout,
|
||||
})
|
||||
|
||||
function RootLayout() {
|
||||
const { pathname } = useLocation()
|
||||
|
||||
// 路由切换时滚动到页面顶部
|
||||
useEffect(() => {
|
||||
window.scrollTo(0, 0)
|
||||
}, [pathname])
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col">
|
||||
<Header />
|
||||
<main className="flex-1">
|
||||
<Outlet />
|
||||
</main>
|
||||
<Footer />
|
||||
<ScrollToTop />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user