提交 16cdcd70 作者: 翁进城

修正NavHeader在刷新后定位

上级 42d73177
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
width: 28px !important; width: 28px !important;
height: 6px !important; height: 6px !important;
background: #ffffff; background: #ffffff;
border-radius: 8px; border-radius: 2px;
transform: translateX(30px); transform: translateX(30px);
} }
} }
......
...@@ -2,9 +2,7 @@ import React, { useState } from 'react'; ...@@ -2,9 +2,7 @@ import React, { useState } from 'react';
import { Avatar, Button, Space, Tabs } from 'antd'; import { Avatar, Button, Space, Tabs } from 'antd';
import type { TabsProps } from 'antd'; import type { TabsProps } from 'antd';
import styles from './index.module.scss'; import styles from './index.module.scss';
import { useNavigate } from 'react-router-dom'; import { useLocation, useNavigate } from 'react-router-dom';
console.log('style', styles);
const items: TabsProps['items'] = [ const items: TabsProps['items'] = [
...@@ -40,18 +38,24 @@ const items: TabsProps['items'] = [ ...@@ -40,18 +38,24 @@ const items: TabsProps['items'] = [
export default function NavHeader() { export default function NavHeader() {
const navigate = useNavigate(); const navigate = useNavigate();
const [key, setKey] = useState('/home'); const location = useLocation();
const currentPath = location.pathname;
console.log('currentHash', location);
const onChange = (key: string) => { const onChange = (key: string) => {
console.log(key); console.log(key);
navigate(key) navigate(key)
setKey(key);
}; };
return ( return (
<div className={styles.navHeader}> <div className={styles.navHeader}>
<div className={styles.logo}></div> <div className={styles.logo}></div>
<Tabs className={styles.tabs} defaultActiveKey='/home' items={items} onChange={onChange} /> <Tabs
className={styles.tabs}
defaultActiveKey={currentPath}
items={items}
onChange={onChange}
/>
<Space size={16} className={styles.btns}> <Space size={16} className={styles.btns}>
<Button type='primary' className={styles.btn1}> <Button type='primary' className={styles.btn1}>
发布信息 发布信息
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论