Skip to content

Allow bypassing client router for nav and sidebar links in theme config #5042

@ciscoo

Description

@ciscoo

Is your feature request related to a problem? Please describe.

It's currently possible to bypass the client router in Markdown files with:

[Link to pure.html](/pure.html){target="_self"}

And with the target specified in an anchor tag:

<a href="/pure.html) target="_self">Link to pure.html</a>

But it's not possible to do the same in the theme config:

import { defineConfig } from "vitepress";

export default defineConfig({
  themeConfig: {
    nav: [
      { text: "Example", link: "/example/index.html" },
    ],

    sidebar: [
      {
        text: "Examples",
        items: [
          { text: "Example", link: "/example/index.html" }
        ],
      },
    ]
  },
});

The above links will be intercepted by the client router resulting in a 404 not found. But navigating directly to the page bypasses the router.

Describe the solution you'd like

It would be nice if there was option to specify the link should not go through the router. For example:

import { defineConfig } from "vitepress";

export default defineConfig({
  themeConfig: {
    nav: [
-     { text: "Example", link: "/example/index.html" },
+     { text: "Example", link: "/example/index.html", direct: true },
    ],

    sidebar: [
      {
        text: "Examples",
        items: [
-          { text: "Example", link: "/example/index.html" }
+          { text: "Example", link: "/example/index.html", direct: true }
        ],
      },
    ]
  },
});

This could result in the nav or sidebar links having the added target="_blank" when direct: true is specified.

Describe alternatives you've considered

I could try to customize the default theme, but I'd rather not and prefer to use the default theme and its components as much as possible.

Additional context

I'm trying to use VitePress for user guide documentation for a Java project. I generate Javadoc to the public/ folder and want to serve the Javadoc from there. Structure looks like:

Project structure
.
├── .vitepress
├── api-examples.md
├── documentation.gradle.kts
├── index.md
├── markdown-examples.md
├── package-lock.json
├── package.json
└── public
    ├── javadoc
    │   ├── allclasses-index.html
    │   ├── allpackages-index.html
    │   ├── element-list
    │   ├── help-doc.html
    │   ├── index-all.html
    │   ├── index.html
    │   ├── io
    │   │   └── mateo
    │   │       └── example
    │   │           ├── Example.html
    │   │           ├── package-summary.html
    │   │           └── package-tree.html
    │   ├── legal
    │   │   ├── ADDITIONAL_LICENSE_INFO
    │   │   ├── ASSEMBLY_EXCEPTION
    │   │   ├── dejavufonts.md
    │   │   ├── jquery.md
    │   │   ├── jqueryUI.md
    │   │   └── LICENSE
    │   ├── member-search-index.js
    │   ├── module-search-index.js
    │   ├── overview-tree.html
    │   ├── package-search-index.js
    │   ├── resource-files
    │   │   ├── copy.svg
    │   │   ├── fonts
    │   │   │   ├── dejavu.css
    │   │   │   ├── DejaVuLGCSans-Bold.woff
    │   │   │   ├── DejaVuLGCSans-Bold.woff2
    │   │   │   ├── DejaVuLGCSans-BoldOblique.woff
    │   │   │   ├── DejaVuLGCSans-BoldOblique.woff2
    │   │   │   ├── DejaVuLGCSans-Oblique.woff
    │   │   │   ├── DejaVuLGCSans-Oblique.woff2
    │   │   │   ├── DejaVuLGCSans.woff
    │   │   │   ├── DejaVuLGCSans.woff2
    │   │   │   ├── DejaVuLGCSansMono-Bold.woff
    │   │   │   ├── DejaVuLGCSansMono-Bold.woff2
    │   │   │   ├── DejaVuLGCSansMono-BoldOblique.woff
    │   │   │   ├── DejaVuLGCSansMono-BoldOblique.woff2
    │   │   │   ├── DejaVuLGCSansMono-Oblique.woff
    │   │   │   ├── DejaVuLGCSansMono-Oblique.woff2
    │   │   │   ├── DejaVuLGCSansMono.woff
    │   │   │   ├── DejaVuLGCSansMono.woff2
    │   │   │   ├── DejaVuLGCSerif-Bold.woff
    │   │   │   ├── DejaVuLGCSerif-Bold.woff2
    │   │   │   ├── DejaVuLGCSerif-BoldItalic.woff
    │   │   │   ├── DejaVuLGCSerif-BoldItalic.woff2
    │   │   │   ├── DejaVuLGCSerif-Italic.woff
    │   │   │   ├── DejaVuLGCSerif-Italic.woff2
    │   │   │   ├── DejaVuLGCSerif.woff
    │   │   │   └── DejaVuLGCSerif.woff2
    │   │   ├── glass.svg
    │   │   ├── jquery-ui.min.css
    │   │   ├── left.svg
    │   │   ├── link.svg
    │   │   ├── right.svg
    │   │   ├── stylesheet.css
    │   │   └── x.svg
    │   ├── script-files
    │   │   ├── jquery-3.7.1.min.js
    │   │   ├── jquery-ui.min.js
    │   │   ├── script.js
    │   │   ├── search-page.js
    │   │   └── search.js
    │   ├── search.html
    │   ├── tag-search-index.js
    │   └── type-search-index.js
    └── robots.txt

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions