Skip to content

Commit d714326

Browse files
authored
fix: link error when base url exsits (#3700)
1 parent 6289d31 commit d714326

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

.changeset/few-buttons-carry.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@modern-js/doc-core': patch
3+
---
4+
5+
fix(doc-core): link error when base url exsits
6+
7+
fix(doc-core): 修复存在 base url 时链接错误的问题

packages/cli/doc-core/src/theme-default/layout/DocLayout/docComponents/link.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ComponentProps } from 'react';
22
import styles from './index.module.scss';
3-
import { withBase, useLang, usePageData } from '@/runtime';
3+
import { withBase, useLang, usePageData, removeBase } from '@/runtime';
44
import { isExternalUrl, normalizeSlash } from '@/shared/utils';
55

66
export const A = (props: ComponentProps<'a'>) => {
@@ -11,7 +11,7 @@ export const A = (props: ComponentProps<'a'>) => {
1111
if (defaultLang && !isExternalUrl(href) && !href.startsWith('#')) {
1212
href = normalizeSlash(href);
1313
// Add lang prefix if not default lang
14-
if (lang !== defaultLang && !href.startsWith(`/${lang}`)) {
14+
if (lang !== defaultLang && !removeBase(href).startsWith(`/${lang}`)) {
1515
href = `/${lang}${href}`;
1616
}
1717

0 commit comments

Comments
 (0)