Repository navigation
Bug: Docsify's path handling is problematic (and broken in some scenarios) #1891
Description
Bug Report
Docsify's default path handling is problematic and/or broken in several scenarios:
-
Docsify's path behavior is inconsistent
Docsify handles paths differently for links and other resources like images and embedded content. This inconsistency requires users to research and memorize how and why path behavior varies based on resource type which is unnecessarily confusing and makes Docsify unintuitive for users. -
Docsify's relative path behavior is non-standard
Relative paths are generally expected to be relative to the context in which they are used. In the context of a website made up of a collection of separate pages, this means relative paths should be relative to the page where they are used. This provides document portability by allowing links between documents and resources to remain intact as they are moved throughout the hierarchy so long as their location relative to each other remains the same.- 🟢 Docsify treats relative non-link paths (images, embedded content, ...) as relative to the current page route. This is the correct behavior for relative paths.
- 🟡 Docsify treats relative link paths as relative to a site's
index.htmlroute. This makes sense from a technical perspective, but this is not expected behavior based on how relative paths work elsewhere. For sites with a flat hierarchy where theindex.htmland markdown pages are located at the root (/) this isn't an issue, but for sites with nested routes (e.g.,/dir/page.md) or a nestedindex.html(e.g.,/docs/index.html) this results in confusion, the need to use unintuitive paths, and broken or incorrect links.
-
Docsify's absolute path behavior is non-standard
Absolute paths are generally expected to be relative to the top-most level in a domain or directory hierarchy. In the context of a Docsify site, this most commonly means the root of the domain (/), but nested sites (/docs/index.html) may prefer to have absolute paths relative to theindex.htmlroute for site portability. This provides consistent and reliable paths to resources from any level within the hierarchy (e.g., accessing/assets/image.pngfrom/,/foo/, or/foo/bar/baz).- 🟡 Docsify treats absolute non-link paths (images, embedded content, ...) as relative to the current page route. This is not how absolute paths work elsewhere which causes confusion, the need to use unintuitive paths, and broken or incorrect links.
- 🟡 Docsify treats relative link paths as relative to a site's
index.htmlroute. This is not how absolute paths work elsewhere which causes confusion, the need to use unintuitive paths, and broken or incorrect links. - 🔴 Docsify's handling of absolute paths prevents absolute paths from being used to access resources above the site's level in the hierarchy. For example, it is not possible to access
/assets/image.pngfrom/dir/page.mdusing an absolute URL.
-
Docsify's absolute path behavior is broken for nested routes
🔴 In Docsify attempt to treat absolute non-link paths (images, embedded content, ...) as relative to the current page route, it incorrectly adds the current page route to paths that already contain the page route. For example:[Root] └─ docs ├─ dir │ ├─ image.png │ └─ page.md ├─ index.html └─ README.md<!-- /docs/dir/page.md --> 
Result:
<img src="/dir/dir/image.png">
-
Docsify does not provide a way to modify or opt-out of its problematic handling of absolute paths
This has led users resorting to using HTML instead of markdown and PRs like fix: render image in absolute path #1868 which propose working around these issues by introducing more options or custom markdown syntax. None of these would be necessary if paths simply worked the way people expected them to by default. Docsify does offer configuration options likebasePathandrelativePath, but neither of these issues allows paths in Docsify to work the way they do outside of Docsify and as people expect them to.
The result has been many issues and PRs that remain unresolved. These are the ones I've found from a very simple search for "absolute" and "relative". There are most likely others that are not accounted for here.
- Can not get right routes with multi sections #2370
- image url begin with "/" should be AbsolutePath,not RelativePath #2369
routeRewrite/redirectsupport likealias#1982- Did not load homepage in router mode history and subdirectory #1763
- relativepath=true and _sidebar.md can't coexist #1761
- relative paths of links in sidebar should be relative to the sidebar file #1684
- using relativePath sidebar sublevels do not render if I use direct link to a page. #1631
- sidebar relative path issues #1569
- Unable to use absolute path for coverpage, loadNavbar, or loadSidebar options #1407
- “Embed files” doesn't effect #1033
- How to add images from root? #850
- When
relativePath: true, even absolute paths are for icons in sidebar are resolved as relative. #877 - Same-level, sub-folder links, don't resolve properly #424
- Version 4.6.8 broke images (404) #415
- router bug #2570
Steps to reproduce
To help others understand the problem, I have created a demo link and non-link paths can be tested:
What is current behaviour
Test results from the Codesandbox Demo can be seen in the following table:
What is the expected behaviour
- Paths should be consistent for all resource types.
- All relative paths should be relative to the page in which they are used by default.
- All absolute paths should be relative to the top-most level in the domain or directory hierarchy by default.
- Configuration options should allow users to define base paths for relative and absolute links:
basePath: Defaults tonull. Functionally the same as settingrelativeBasePathandabsoluteBasePathto the same value.relativeBasePath: Defaults to current page route. OverridesbasePath.absoluteBasePath: Defaults to/. OverridesbasePath.
- A
:basepathmarkdown attribute (or similar) should allows specifying the base path for individual elements. This is required to allow accessing resources outside of the currentindex.htmlroute when one of the base path options above would otherwise prevent it. For example:[Root] ├─ assets │ └─ image.png └─ docs ├─ index.html └─ README.mdwindow.docsify = { basePath: '/docs/` }
Result:<!-- /docs/README.md -->  
<img src="/assets/image.png"> <img src="/assets/image.png">
If these changes are implemented, the default behavior will be as follows:


Activity
[-]Bug: Docsify's path handling is problematic and/or broken[/-][+]Bug: Docsify's path handling is problematic (and broken in some scenarios)[/+]Koooooo-7 commentedon Sep 20, 2022
@jhildenbiddle I agree with you about the
path issuesin docsify and the whole pic designs which we need take care.About the
:basepathconfig, It indicates the base path directly with/ path/or even../path/scenarios, if we support the newpathconfig, I think we may need refactorgetAndRemoveConfig#1825 in advance.loprx commentedon Jul 22, 2023
Hi, I am currently encountering the problem of resolving absolute paths to relative paths, using the basepath mentioned in the issue, but it did not solve the problem.
johnfercher commentedon Aug 18, 2023
Any news in this issue?
L-Super commentedon Feb 9, 2024
I am currently encountering issue 2, and I do not want to change my document directory structure. Is there any way to resolve this?
Koooooo-7 commentedon Feb 9, 2024
Hi @L-Super , could provide more details on your issue? and I may find a workaround to solve it before we settle this issue down.
For path related issue, consider try
aliasor rewrite it in hooks instead of re- structure your docs totally.L-Super commentedon Feb 10, 2024
I placed this repo under the docs folder and renamed SUMMARY.md to guide.md, while my directory structure for docs is as follows:

index.html:
root guide.md:
Directory structure:
When I switch between different sections from the left side, the URL shows an incorrect path.
Current behaviour:
Expected behaviour:
Koooooo-7 commentedon Feb 10, 2024
Hi @L-Super , I think you can try the
aliasconfig to do the trick.You can refer our docs here to see how it works on live, we rewrite routes also, see the behavior in our site docsify here.
docsify/docs/index.html
Line 77 in cec43d7
And if you could make a PR on your own repo (or other new place ) with the changes you mentioned above ( I could fork and reproduce it ).
I can help you to find a feasible solution as well.
L-Super commentedon Feb 10, 2024
I created my repo, you can reprodeuce it.
Koooooo-7 commentedon Feb 11, 2024
Hi @L-Super In order not mess up this main assumption on this issue, I move it to #2370 .
trusktr commentedon Feb 12, 2024
Thank you John for making this extensive tracking of all the URL problems. I haven't read the whole issue, but we should eliminate custom URL handling and use the standardized
URLAPI, and paths should be have as they do naturally in vanilla web (basically we simply add.mdis a browsable file type for web sites, but we should not otherwise change standard path behavior).chetta19 commentedon Nov 6, 2024
Hi, I've hit this bug while using alias and images and I was wondering if there is any progress on fixing it or a workaround?
Koooooo-7 commentedon Nov 12, 2024
Hi @chetta19 , the image relative path isn't consistent to the generic behavior for now. If you have to use it.
I suppose you may have a try on building an image link post processor as an afterEach hook, which could filter links and convert it to what your expectation is.
emendir commentedon Sep 4, 2025
Is this issue being worked on?
Handling hyperlink paths properly is a pretty essential thing in the World Wide Web!
sy-records commentedon Sep 5, 2025
I'm not sure if some fixes were made in #2579, but if any new issues arise, feel free to submit an issue.
emendir commentedon Sep 5, 2025
Does that mean we can expect the issue to be fixed in the next release, probably version 5.0.0?
sy-records commentedon Sep 5, 2025
Maybe. I just released version v5.0.0-rc.3. You can give it a try.
emendir commentedon Sep 5, 2025
I tested v5.0.0-rc.3, and path handling is still broken. Attached is the simplest possible demo I could put together.
Again, the link behaviour is inconsistently wrong. Here's the project structure:
Here's the docsify config in
DemoProject/index.html:I played around with using different markdown files as the home-page, and the results were inconsistent.
docs/Docs-ReadMe.mdis opened as the homepage, relative references to embedded images don't workReadMe.mdis set as the homepage, anddocs/Docs-ReadMe.mdis opened, the absolute references to embedded images don't work, but the absolute hyperlink to the ReadMe.md file doesDocsifyDemo.zip
":include"a remote markdown file, and all the relative URLs should be relative to that. #1977 as a duplicate of this issue