Compare commits

...

2 Commits

2 changed files with 5 additions and 2 deletions

View File

@ -108,7 +108,10 @@ export const Article: Component<ArticleProps & ParentProps> = (props) => {
if (href.startsWith("#")) return;
e.preventDefault();
navigate(href);
// Resolve relative hrefs against the current page path so that
// e.g. "blah.md" on /content/page.md becomes /content/blah.md
const resolved = new URL(href, window.location.origin + window.location.pathname).pathname;
navigate(resolved);
};
dom.addEventListener("click", onClick);

View File

@ -115,7 +115,7 @@ export const HeadingNode: Component<{
if (e.button === 0) {
// Left-click: use SPA navigation
e.preventDefault();
navigate(href());
navigate(`${props.basePath}#${anchor}`);
}
// Middle-click / right-click: let the browser handle the <a> natively
// 滚动到目标元素,考虑导航栏高度偏移