fix(router): standardize link and resource path resolution - #2793
fix(router): standardize link and resource path resolution#2793sy-records wants to merge 2 commits into
Conversation
- resolve relative paths from the current Markdown page - resolve absolute paths from the domain root - add configurable and per-element base path overrides - prevent duplicate base paths and preserve sidebar activation - add regression tests and configuration documentation Fixes #1891
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
||
| expect(output).toMatchInlineSnapshot( | ||
| '"<p><a href="#/url" target="_blank">alt text</a></p>"', | ||
| '"<p><a href="/#/url" target="_blank">alt text</a></p>"', |
There was a problem hiding this comment.
Is this ok without the leading hash symbol?
There was a problem hiding this comment.
Yes, /#/url is correct. The hash symbol is present — it's the / (domain root) followed by #/url (the hash route). In hash routing, links resolve to /<base>#/<path>, so the leading / comes first. This matches the output of HashHistory.toURL which returns '#' + super.toURL(...) prepended to the site root path.
| import { History } from '../../src/core/router/history/base.js'; | ||
|
|
||
| class MockHistory extends History { | ||
| mode = 'hash'; |
There was a problem hiding this comment.
Are we testing both modes? Need to test both. @copilot make sure the same tests run in both modes.
There was a problem hiding this comment.
Done. Refactored the file to use a runBaseHistoryTests(label, HistoryClass) helper that defines all the suites once and runs them for both MockHistory (hash mode) and MockHTML5History (history mode). All 24 tests pass (12 per mode). Both modes test relativePath: true, relativePath: false, default path behavior, and getFile.
|
Getting ready for 6.0 I see! |
Summary
Standardize path handling for links, images, and embedded resources.
This change:
relativeBasePathandabsoluteBasePathconfiguration options.:basepathMarkdown attribute.basePathsources.No UI changes are introduced, so before/after screenshots are not applicable.
Related issue, if any:
Fixes #1891
What kind of change does this PR introduce?
For any code change,
Does this PR introduce a breaking change?
Relative links are now resolved from the current Markdown page by default because
relativePathdefaults totrue. Applications that depend on the previous index-relative behavior can restore it with:Absolute paths now resolve from the domain root. Sites that want absolute paths rooted at the Docsify site directory can configure
absoluteBasePath.The default
basePathvalue is nownullinstead of an empty string.Tested in the following browsers: