feat: 路由改造

This commit is contained in:
zdl
2025-10-17 18:59:00 +08:00
parent 02bf1ea709
commit bae4d25e24
15 changed files with 496 additions and 227 deletions

View File

@@ -0,0 +1,27 @@
// src/components/ScrollToTop/index.js
// 路由切换时自动滚动到页面顶部
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
/**
* ScrollToTop - 路由切换时自动滚动到顶部
*
* 使用方式:在 App.js 的 Router 内部添加此组件
*
* @example
* <BrowserRouter>
* <ScrollToTop />
* <Routes>...</Routes>
* </BrowserRouter>
*/
export default function ScrollToTop() {
const { pathname } = useLocation();
useEffect(() => {
// 路径改变时滚动到顶部
window.scrollTo(0, 0);
}, [pathname]);
return null;
}