mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-04 18:37:53 +02:00
fix(v2): allow external links in doc sidebar (#2186)
* fix(v2): allow external links in doc sidebar * Fix for ESLint
This commit is contained in:
parent
8065e5f9dd
commit
705b496397
3 changed files with 22 additions and 6 deletions
|
@ -10,6 +10,7 @@ import classnames from 'classnames';
|
|||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
import useBaseUrl from '@docusaurus/useBaseUrl';
|
||||
import Link from '@docusaurus/Link';
|
||||
import isInternalUrl from '@docusaurus/utils'; // eslint-disable-line import/no-extraneous-dependencies
|
||||
|
||||
import styles from './styles.module.css';
|
||||
|
||||
|
@ -70,11 +71,18 @@ function DocSidebarItem({item, onItemClick, collapsible}) {
|
|||
return (
|
||||
<li className="menu__list-item" key={label}>
|
||||
<Link
|
||||
activeClassName="menu__link--active"
|
||||
className="menu__link"
|
||||
exact
|
||||
to={href}
|
||||
onClick={onItemClick}>
|
||||
{...(isInternalUrl(href)
|
||||
? {
|
||||
activeClassName: 'menu__link--active',
|
||||
exact: true,
|
||||
onClick: onItemClick,
|
||||
}
|
||||
: {
|
||||
target: '_blank',
|
||||
rel: 'noreferrer noopener',
|
||||
})}>
|
||||
{label}
|
||||
</Link>
|
||||
</li>
|
||||
|
|
|
@ -7,13 +7,12 @@
|
|||
|
||||
import React, {useEffect, useRef} from 'react';
|
||||
import {NavLink} from 'react-router-dom';
|
||||
|
||||
const internalRegex = /^\/(?!\/)/;
|
||||
import isInternalUrl from '@docusaurus/utils';
|
||||
|
||||
function Link(props) {
|
||||
const {to, href} = props;
|
||||
const targetLink = to || href;
|
||||
const isInternal = internalRegex.test(targetLink);
|
||||
const isInternal = isInternalUrl;
|
||||
const preloaded = useRef(false);
|
||||
|
||||
const IOSupported =
|
||||
|
|
9
packages/docusaurus/src/client/exports/utils.js
Normal file
9
packages/docusaurus/src/client/exports/utils.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
export default function isInternalUrl(url) {
|
||||
return /^\/(?!\/)/.test(url);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue