From c2637185ae746d4407c8ee22dfa61b278f37f3b8 Mon Sep 17 00:00:00 2001 From: Robert Broersma Date: Sun, 29 Mar 2020 16:52:39 +0200 Subject: [PATCH] Forward refs to anchors in Link --- packages/router/src/links.js | 40 ++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/packages/router/src/links.js b/packages/router/src/links.js index 389b0494e265..b08a3e6c24d6 100644 --- a/packages/router/src/links.js +++ b/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) => ( { event.preventDefault() navigate(to) }} /> -) +)) -const NavLink = ({ to, className, activeClassName, ...rest }) => { - const context = useContext(LocationContext) - const theClassName = to === context.pathname ? activeClassName : className - return ( - { - event.preventDefault() - navigate(to) - }} - /> - ) -} +const NavLink = forwardRef( + ({ to, className, activeClassName, ...rest }, ref) => { + const context = useContext(LocationContext) + const theClassName = to === context.pathname ? activeClassName : className + return ( + { + event.preventDefault() + navigate(to) + }} + /> + ) + } +) export { Link, NavLink }