Skip to content

Commit

Permalink
Forward refs to anchors in Link
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBroersma committed Mar 29, 2020
1 parent 11166d7 commit c263718
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions packages/router/src/links.js
@@ -1,32 +1,36 @@
import { useContext } from 'react'
import { useContext, forwardRef } from 'react'

import { LocationContext, navigate } from './internal'

const Link = ({ to, ...rest }) => (
const Link = forwardRef(({ to, ...rest }, ref) => (
<a
href={to}
ref={ref}
{...rest}
onClick={(event) => {
event.preventDefault()
navigate(to)
}}
/>
)
))

const NavLink = ({ to, className, activeClassName, ...rest }) => {
const context = useContext(LocationContext)
const theClassName = to === context.pathname ? activeClassName : className
return (
<a
href={to}
className={theClassName}
{...rest}
onClick={(event) => {
event.preventDefault()
navigate(to)
}}
/>
)
}
const NavLink = forwardRef(
({ to, className, activeClassName, ...rest }, ref) => {
const context = useContext(LocationContext)
const theClassName = to === context.pathname ? activeClassName : className
return (
<a
href={to}
ref={ref}
className={theClassName}
{...rest}
onClick={(event) => {
event.preventDefault()
navigate(to)
}}
/>
)
}
)

export { Link, NavLink }

0 comments on commit c263718

Please sign in to comment.