remove automatic withBaseUrl in Link

This commit is contained in:
slorber 2020-07-28 17:16:29 +02:00
parent d25d4b08f6
commit 4247fc4bb1
2 changed files with 5 additions and 10 deletions

View file

@ -28,6 +28,9 @@ function NavLink({
activeClassName?: string;
prependBaseUrlToHref?: string;
} & 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 normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});
return (
@ -41,7 +44,7 @@ function NavLink({
: {
isNavLink: true,
activeClassName,
to,
to: toUrl,
...(activeBasePath || activeBaseRegex
? {
isActive: (_match, location) =>

View file

@ -11,7 +11,6 @@ import {NavLink, Link as RRLink} from 'react-router-dom';
import isInternalUrl from './isInternalUrl';
import ExecutionEnvironment from './ExecutionEnvironment';
import {useLinksCollector} from '../LinksCollector';
import {useBaseUrlUtils} from './useBaseUrl';
declare global {
interface Window {
@ -38,20 +37,13 @@ function Link({
'data-noBrokenLinkCheck': noBrokenLinkCheck,
...props
}: Props): JSX.Element {
const {withBaseUrl} = useBaseUrlUtils();
const linksCollector = useLinksCollector();
// IMPORTANT: using to or href should not change anything
// For example, MDX links will ALWAYS give us the href props
// Using one prop or the other should not be used to distinguish
// internal links (/docs/myDoc) from external links (https://github.com)
const targetLinkUnprefixed = to || href;
// Automatically apply base url in links
const targetLink =
typeof targetLinkUnprefixed !== 'undefined'
? withBaseUrl(targetLinkUnprefixed)
: undefined;
const targetLink = to || href;
const isInternal = isInternalUrl(targetLink);
const preloaded = useRef(false);