forked from redwoodjs/redwood
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11166d7
commit c263718
Showing
1 changed file
with
22 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } |