mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-02 19:03:38 +02:00
remove automatic withBaseUrl in Link
This commit is contained in:
parent
d25d4b08f6
commit
4247fc4bb1
2 changed files with 5 additions and 10 deletions
|
@ -28,6 +28,9 @@ function NavLink({
|
||||||
activeClassName?: string;
|
activeClassName?: string;
|
||||||
prependBaseUrlToHref?: string;
|
prependBaseUrlToHref?: string;
|
||||||
} & ComponentProps<'a'>) {
|
} & ComponentProps<'a'>) {
|
||||||
|
// TODO all this seems hacky
|
||||||
|
// {to: 'version'} should probably be forbidden, in favor of {to: '/version'}
|
||||||
|
const toUrl = useBaseUrl(to);
|
||||||
const activeBaseUrl = useBaseUrl(activeBasePath);
|
const activeBaseUrl = useBaseUrl(activeBasePath);
|
||||||
const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});
|
const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});
|
||||||
return (
|
return (
|
||||||
|
@ -41,7 +44,7 @@ function NavLink({
|
||||||
: {
|
: {
|
||||||
isNavLink: true,
|
isNavLink: true,
|
||||||
activeClassName,
|
activeClassName,
|
||||||
to,
|
to: toUrl,
|
||||||
...(activeBasePath || activeBaseRegex
|
...(activeBasePath || activeBaseRegex
|
||||||
? {
|
? {
|
||||||
isActive: (_match, location) =>
|
isActive: (_match, location) =>
|
||||||
|
|
|
@ -11,7 +11,6 @@ import {NavLink, Link as RRLink} from 'react-router-dom';
|
||||||
import isInternalUrl from './isInternalUrl';
|
import isInternalUrl from './isInternalUrl';
|
||||||
import ExecutionEnvironment from './ExecutionEnvironment';
|
import ExecutionEnvironment from './ExecutionEnvironment';
|
||||||
import {useLinksCollector} from '../LinksCollector';
|
import {useLinksCollector} from '../LinksCollector';
|
||||||
import {useBaseUrlUtils} from './useBaseUrl';
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
|
@ -38,20 +37,13 @@ function Link({
|
||||||
'data-noBrokenLinkCheck': noBrokenLinkCheck,
|
'data-noBrokenLinkCheck': noBrokenLinkCheck,
|
||||||
...props
|
...props
|
||||||
}: Props): JSX.Element {
|
}: Props): JSX.Element {
|
||||||
const {withBaseUrl} = useBaseUrlUtils();
|
|
||||||
const linksCollector = useLinksCollector();
|
const linksCollector = useLinksCollector();
|
||||||
|
|
||||||
// IMPORTANT: using to or href should not change anything
|
// IMPORTANT: using to or href should not change anything
|
||||||
// For example, MDX links will ALWAYS give us the href props
|
// For example, MDX links will ALWAYS give us the href props
|
||||||
// Using one prop or the other should not be used to distinguish
|
// Using one prop or the other should not be used to distinguish
|
||||||
// internal links (/docs/myDoc) from external links (https://github.com)
|
// internal links (/docs/myDoc) from external links (https://github.com)
|
||||||
const targetLinkUnprefixed = to || href;
|
const targetLink = to || href;
|
||||||
|
|
||||||
// Automatically apply base url in links
|
|
||||||
const targetLink =
|
|
||||||
typeof targetLinkUnprefixed !== 'undefined'
|
|
||||||
? withBaseUrl(targetLinkUnprefixed)
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const isInternal = isInternalUrl(targetLink);
|
const isInternal = isInternalUrl(targetLink);
|
||||||
const preloaded = useRef(false);
|
const preloaded = useRef(false);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue