Skip to content

Commit a5ece97

Browse files
committed
fix: 修正导航栏无法正确高亮的bug
1 parent bd94379 commit a5ece97

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/App.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@ const StyledLink = styled(Link)(({ theme }) => ({
7272
function NavLinks() {
7373
const location = useLocation();
7474

75-
// 修复路由匹配逻辑,使用hash路由的pathname
75+
// 精确匹配当前路由路径
7676
const isActive = (path: string) => {
77-
const hashPath = location.hash.replace('#', '');
78-
if (path === '/') return hashPath === '/';
79-
return hashPath.startsWith(path);
77+
const currentPath = location.pathname;
78+
return currentPath === path;
8079
};
8180

8281
return (
@@ -96,7 +95,7 @@ function NavLinks() {
9695

9796
function MainApp() {
9897
return (
99-
<Router basename="/">
98+
<Router>
10099
<AppBar
101100
position="static"
102101
color="default"

0 commit comments

Comments
 (0)