第一次点击锚点,会刷新页面,重新渲染,不管是a标签还是antd的Anchor都会,但是我看antd的demo就没有这个问题?路由用的umi
锚点代码
<Anchor style={{ position: 'fixed', right: '10%', top: '50%' }}>
<Link href="#ProductOverview" title="第1个锚点" />
<Link href="#PositionTestPortfolio" title="第2个锚点" />
<Link href="#PerformanceAnalysis" title="第3个锚点" />
<Link href="#ScenarioAnalysis2" title="第4个锚点" />
<Link href="#top" title="返回顶部" />
</Anchor>
路由配置
`
hash: true,
antd: {},
dva: {
hmr: true,
},
locale: {
default: 'zh-CN',
antd: true,
baseNavigator: true,
},
dynamicImport: {
loading: '@/components/xx',
},
targets: {
ie: 11,
},
`
hash路由监听#后的hash值跳转页面, 锚点改变的就是hash值, 其实你的页面不是在刷新, 而是在跳转
帮你搜了篇文章hash 路由如何使用锚点