Skip to content

Commit 4db8cdf

Browse files
Fix docs router link freeze
1 parent d9d7401 commit 4db8cdf

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

src/components/DocsLayout.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,8 @@ export function DocsLayout({
848848
})
849849
}, [groupInitialOpenState])
850850

851+
const libraryHomePath = `/${libraryId}/${version}`
852+
851853
const menuItems = menuConfig.map((group, i) => {
852854
const groupKey = `${i}:${String(group.label)}`
853855

@@ -919,8 +921,7 @@ export function DocsLayout({
919921
</a>
920922
) : isHomeLink ? (
921923
<Link
922-
to="/$libraryId/$version"
923-
params={{ libraryId, version }}
924+
to={libraryHomePath}
924925
onClick={() => {
925926
detailsRef.current.removeAttribute('open')
926927
}}

src/components/markdown/MarkdownLink.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ function isRoutableInternalLink(link: string) {
2929
)
3030
}
3131

32+
function normalizeRoutableInternalPathname(pathname: string) {
33+
const routerFrameworkMatch = pathname.match(
34+
/^\/router\/([^/]+)\/docs\/framework\/[^/]+\/(.+)$/,
35+
)
36+
37+
if (!routerFrameworkMatch) {
38+
return pathname
39+
}
40+
41+
const [, version, docsPath] = routerFrameworkMatch
42+
43+
if (!version || !docsPath || docsPath.startsWith('examples/')) {
44+
return pathname
45+
}
46+
47+
return `/router/${version}/docs/${docsPath}`
48+
}
49+
3250
export function MarkdownLink({
3351
href: hrefProp,
3452
...rest
@@ -37,14 +55,16 @@ export function MarkdownLink({
3755

3856
if (isRoutableInternalLink(href)) {
3957
const [hrefWithoutHash, hash] = href.split('#')
40-
const hrefWithoutMd = hrefWithoutHash.replace('.md', '')
58+
const hrefWithoutMd = normalizeRoutableInternalPathname(
59+
hrefWithoutHash.replace('.md', ''),
60+
)
4161

4262
return (
4363
<Link
4464
{...rest}
4565
to={hrefWithoutMd}
4666
hash={hash}
47-
preload={undefined}
67+
preload={false}
4868
ref={undefined}
4969
/>
5070
)
@@ -73,7 +93,7 @@ export function MarkdownLink({
7393
unsafeRelative="path"
7494
to={hrefWithoutMd}
7595
hash={hash}
76-
preload={undefined}
96+
preload={false}
7797
ref={undefined}
7898
/>
7999
)

0 commit comments

Comments
 (0)