Skip to content

Commit 3f534be

Browse files
author
vhtmui
committed
feat(docs): 修复导航组件中的链接解析问题
在 Nav.svelte 组件中添加了对 SvelteKit 路径解析的支持, 确保文档导航中的链接能够正确解析和跳转。
1 parent 2669734 commit 3f534be

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/routes/docs/MyMarkdown/Nav.svelte

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<script>
66
import { cn } from '$lib/utils';
77
import { getAstNode } from 'svelte-exmarkdown';
8+
import { resolve } from '$app/paths';
89
910
let { children, class: ClassName, ...restProps } = $props();
1011
@@ -15,10 +16,16 @@
1516

1617
{#snippet node(child)}
1718
{#if child.type === 'element'}
18-
{@const { className, ...restProps } = child.properties || {}}
19+
{@const { className, href, ...restProps } = child.properties || {}}
1920
{@const isTopLevel = className?.includes('toc-level-1')}
2021
{@const csn = cn(className, isTopLevel ? 'menu' : '')}
21-
<svelte:element this={child.tagName === 'ol' ? 'ul' : child.tagName} class={csn} {...restProps}>
22+
<svelte:element
23+
this={child.tagName === 'ol' ? 'ul' : child.tagName}
24+
class={csn}
25+
{...restProps}
26+
,
27+
href={href ? resolve(href) : undefined}
28+
>
2229
{#if isTopLevel}
2330
<li class="menu-title">OutLine</li>
2431
{/if}

0 commit comments

Comments
 (0)