core icon indicating copy to clipboard operation
core copied to clipboard

[Bug report] `linksPlugin` cannot correctly identify whether it is an external link.

Open pengzhanbo opened this issue 6 months ago • 1 comments

Description

The linksPlugin does not accurately reflect whether a link is external.

The issue is that the default logic of isExternal simplistically considers links that do not start with base and do not end with .md as external links.

However, this handling is inappropriate. When a site's base is /docs/ and the page is configured with permalink: /guide/foo/, using [foo](/guide/foo/) in markdown will mistakenly be identified as an external link.

In reality, it should concatenate with base and be recognized as an internal link rather than an external one.

/guide/foo.md

---
permalink: /guide/foo/
---

README.md

[jump to /guide/foo/](/guide/foo/)
[jump to ./guide/foo.md](./guide/foo.md)

I believe that the formatting of the two links should be consistent, and that /guide/foo/ should not be treated as an external link.


Solution

I believe the linksPlugin does not need to make unnecessary judgments about whether a link is external or not. It lacks information such as pages -> path, which leads to inaccurate results.

We can fully delegate this functionality to the RouteLink or AutoLink components to handle. With the existence of routes.js, it can help us accurately determine whether a link is external.

Reproduction

https://stackblitz.com/edit/vuepress-vzbywlkp?file=docs%2FREADME.md

Used Package Manager

pnpm

System Info

-

pengzhanbo avatar Jun 11 '25 03:06 pengzhanbo

我也遇到相同的问题,我觉得可以允许存在 自动识别,但是要有一个优先级,默认自动识别链接类型,但是如果使用者在 config.jsnavbar 手动配置了 link:"...",那就识别为连接,否则就是普通路由

mulining avatar Jun 16 '25 07:06 mulining

This issue is marked as stale because it has not had recent activity. Issues marked with stale will be closed if they have no activity within 7 days.

github-actions[bot] avatar Jul 02 '25 01:07 github-actions[bot]

~As a workaround, the current isExternal option could help - set it to () => false.~

I see. The original reason is that we treat md file link as internal links conventionally. We can consider remove this convention.

meteorlxy avatar Aug 05 '25 08:08 meteorlxy