ant-design/components/anchor/demo/onClick.md

46 lines
875 B
Markdown
Raw Normal View History

---
order: 3
title:
zh-CN: 自定义 onClick 事件
en-US: Customize the onClick event
---
## zh-CN
点击锚点不记录历史。
## en-US
Clicking on an anchor does not record history.
2020-01-21 16:21:37 +08:00
```tsx
import React from 'react';
import { Anchor } from 'antd';
const { Link } = Anchor;
2020-01-21 16:21:37 +08:00
const handleClick = (
2020-09-14 19:13:47 +08:00
e: React.MouseEvent<HTMLElement>,
link: {
title: React.ReactNode;
href: string;
},
) => {
e.preventDefault();
console.log(link);
};
const App: React.FC = () => (
<Anchor affix={false} onClick={handleClick}>
<Link href="#components-anchor-demo-basic" title="Basic demo" />
<Link href="#components-anchor-demo-static" title="Static demo" />
<Link href="#API" title="API">
<Link href="#Anchor-Props" title="Anchor Props" />
<Link href="#Link-Props" title="Link Props" />
</Link>
</Anchor>
2018-11-28 15:00:03 +08:00
);
export default App;
```