mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-04 01:09:20 +02:00
refactor(v2): use nav link component only where needed (#2585)
This commit is contained in:
parent
52233f7c44
commit
9c1abcddab
4 changed files with 7 additions and 14 deletions
|
@ -76,6 +76,7 @@ function DocSidebarItem({item, onItemClick, collapsible}) {
|
|||
to={href}
|
||||
{...(isInternalUrl(href)
|
||||
? {
|
||||
isNavLink: true,
|
||||
activeClassName: 'menu__link--active',
|
||||
exact: true,
|
||||
onClick: onItemClick,
|
||||
|
|
|
@ -33,6 +33,7 @@ function NavLink({activeBasePath, to, href, label, position, ...props}) {
|
|||
href,
|
||||
}
|
||||
: {
|
||||
isNavLink: true,
|
||||
activeClassName: 'navbar__link--active',
|
||||
to: toUrl,
|
||||
...(activeBasePath
|
||||
|
|
|
@ -6,15 +6,16 @@
|
|||
*/
|
||||
|
||||
import React, {useEffect, useRef} from 'react';
|
||||
import {NavLink} from 'react-router-dom';
|
||||
import {NavLink, Link as RRLink} from 'react-router-dom';
|
||||
import isInternalUrl from '@docusaurus/isInternalUrl';
|
||||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
||||
|
||||
function Link(props) {
|
||||
function Link({isNavLink, ...props}) {
|
||||
const {to, href} = props;
|
||||
const targetLink = to || href;
|
||||
const isInternal = isInternalUrl(targetLink);
|
||||
const preloaded = useRef(false);
|
||||
const LinkComponent = isNavLink ? NavLink : RRLink;
|
||||
|
||||
const IOSupported = ExecutionEnvironment.canUseIntersectionObserver;
|
||||
|
||||
|
@ -72,7 +73,7 @@ function Link(props) {
|
|||
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
||||
<a {...props} href={targetLink} />
|
||||
) : (
|
||||
<NavLink
|
||||
<LinkComponent
|
||||
{...props}
|
||||
onMouseEnter={onMouseEnter}
|
||||
innerRef={handleRef}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue