Skip to content

relative url start with "../" in nav no longer works #2752

Closed
@akinmr

Description

@akinmr

When I tried to make a link to an external resource in nav section of mkdos.yml, using the following example, the actual output HTML omits "../" in the relative URL and I couldn't point to external resources out of mkdocs with relative URL.
https://www.mkdocs.org/user-guide/configuration/#nav

The minimal mkdocs.yml to reproduce the problem is as follows:

site_name: Example
site_url: https://example.com/foo/

nav:
    - Parent: '../'
    - Sibling: '../some/dir/'
    - Home: './'
    - Index: 'index.md'

When I compile it with empty docs/index.md file, the navigation section in site/index.html became as follows:

<!-- Main navigation -->
<ul class="nav navbar-nav">
    <li class="navitem">
        <a href="./" class="nav-link">Parent</a>
    </li>
    <li class="navitem">
        <a href="some/dir/" class="nav-link">Sibling</a>
    </li>
    <li class="navitem">
        <a href="./" class="nav-link">Home</a>
    </li>
    <li class="navitem active">
        <a href="." class="nav-link">Index</a>
    </li>
</ul>

What I expect was that the link of "Parent" should point to "../"(= https://example.com/) and the link of Sibling should point to "../some/dir"(=https://example.com/some/dir/), which are outside of the generated doc.

I remember this way (Sibling case) worked in past, but when I recompiled the document with the latest mkdocs, it started emitting unexpected URL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions