Skip to content

fix(theme): keep nested parent segments in relative links - #5586

Open
anubhavlal07 wants to merge 1 commit into
vuejs:mainfrom
anubhavlal07:fix/normalize-nested-relative-links
Open

anubhavlal07 wants to merge 1 commit into
vuejs:mainfrom
anubhavlal07:fix/normalize-nested-relative-links

Conversation

@anubhavlal07

Copy link
Copy Markdown

Description

normalizeLink in the default theme loses ../ segments when a relative link goes up more than one directory. VPLink, VPButton and VPNavBarTitle all use it, so hero actions, feature links and nav/sidebar items are affected.

normalizeLink('../foo')       -> '../foo.html'   (ok)
normalizeLink('../../foo.md') -> '../foo.html'   (expected '../../foo.html')

The cause is the regex that keeps the leading dot prefix, /(?:(^\.+)\/)?.*$/. It only captures the first segment (..), and the rest of the URL is rebuilt from new URL(url, 'http://a.com').pathname, which has already resolved every .. away. Any further parent segments are dropped, so the link points at the wrong page.

The fix makes the captured prefix take every leading dot segment: /(?:(^\.+(?:\/\.+)*)\/)?.*$/. Links with zero or one leading segment behave the same as before.

Added unit tests for normalizeLink covering ./, ../, ../../ and ../../../ links with a query and hash.

Linked Issues

None, found while reading the code.

Additional Context

pnpm test:unit (33 files, 528 tests), tsc -p __tests__/unit, pnpm typecheck and prettier all pass.

@netlify

netlify Bot commented Nov 22, 2026

Copy link
Copy Markdown

👷 Deploy request for vitepress-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 2e9998e

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant