Skip to content
This repository was archived by the owner on Apr 6, 2025. It is now read-only.

Commit 5b2c23c

Browse files
author
Jorge Bucaran
committed
Let customize underlying <a> element in Link component.
1 parent 18f51cd commit 5b2c23c

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

src/Link.js

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
11
import { h } from "hyperapp"
22

33
export function Link(props, children) {
4-
var href = props.to
4+
var to = props.to
55
var location = props.location || window.location
66

7-
return h(
8-
"a",
9-
{
10-
href: href,
11-
onclick: function(e) {
12-
if (
13-
e.button !== 0 ||
14-
e.altKey ||
15-
e.metaKey ||
16-
e.ctrlKey ||
17-
e.shiftKey ||
18-
props.target === "_blank" ||
19-
e.currentTarget.origin !== location.origin
20-
) {
21-
} else {
22-
e.preventDefault()
7+
props.href = to
8+
props.onclick = function(e) {
9+
if (
10+
e.button !== 0 ||
11+
e.altKey ||
12+
e.metaKey ||
13+
e.ctrlKey ||
14+
e.shiftKey ||
15+
props.target === "_blank" ||
16+
e.currentTarget.origin !== location.origin
17+
) {
18+
} else {
19+
e.preventDefault()
2320

24-
if (location.pathname !== href) {
25-
history.pushState(location.pathname, "", href)
26-
}
27-
}
21+
if (location.pathname !== to) {
22+
history.pushState(location.pathname, "", to)
2823
}
29-
},
30-
children
31-
)
24+
}
25+
}
26+
27+
return h("a", props, children)
3228
}

0 commit comments

Comments
 (0)