Skip to content

feat: add route option (close #1505)#1538

Open
Mister-Hope wants to merge 4 commits into
mainfrom
route-option
Open

feat: add route option (close #1505)#1538
Mister-Hope wants to merge 4 commits into
mainfrom
route-option

Conversation

@Mister-Hope
Copy link
Copy Markdown
Member

@Mister-Hope Mister-Hope commented Apr 11, 2024

Warning

This PR is now based on #1562, so it's expected #1562 to be merged first.

Tip

For a file like /a/b.md, the full format is /a/b.html and clean format is /a/b

Features

This pr adds route option for vuepress config file.

  • New route.cleanUrl option to support the "clean format"
  • pagePatterns and permalinkPatten is moved to route.pagePatterns and route.permalinkPatten

Bug Fixes

Previously, when use manually set a permalink or page path to a clean format like /a, they will always get 404 when trying to visit the page (in any link format). Now, this is correctly handled. Page path will be normalized to a "full" or "clean" version based on cleanUrl, no matter user use "clean", "full" format or mixing them.

Performance Improvements

Now, the key in routes is always the clean format, which avoid outputting uncessary .html suffix for most pages.

Potential Breaking Changes

  • Now inferRoutePath and normalizeRoutePath return the "clean" format instead of "full" format.

Tweaks

Now a new field called routeKey is on the Page object.

@Mister-Hope Mister-Hope linked an issue Apr 11, 2024 that may be closed by this pull request
@meteorlxy meteorlxy changed the title feat: add route option feat: add route option (close #1505) May 14, 2024
@coveralls
Copy link
Copy Markdown

coveralls commented May 16, 2024

Coverage Report for CI Build 26091267431

Coverage increased (+0.1%) to 73.082%

Details

  • Coverage increased (+0.1%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (30 of 31 lines covered, 96.77%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
packages/core/src/app/prepare/prepareRoutes.ts 1 0 0.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1067
Covered Lines: 776
Line Coverage: 72.73%
Relevant Branches: 549
Covered Branches: 405
Branch Coverage: 73.77%
Branches in Coverage %: Yes
Coverage Strength: 45.87 hits per line

💛 - Coveralls

@Mister-Hope
Copy link
Copy Markdown
Member Author

now e2e test is added in this PR

@Mister-Hope
Copy link
Copy Markdown
Member Author

image

A little weird to me, I can not reproduce the CI result locally

@pengzhanbo
Copy link
Copy Markdown
Member

@Mister-Hope

In the e2e/docs/components/route-link.md file, the title is Query and hash, but in the e2e/tests/components/route-link.spec.ts file, the locator is:

- .e2e-theme-content #hash-and-query + ul > li a
                      ^^^^^^^^^^^^^^
+ .e2e-theme-content #query-and-hash + ul > li a

which causes the e2e test to fail due to the inability to find the element.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#L94-L100

image

The regular expression here does not satisfy path matching after enabling cleanUrl. For strings in the format of /xxx, it always returns false, and the value of href in linksPlugin is skipped during parsing, resulting in /xxx instead of /xxx.html.

The regular expression requires that the path part must end with /, .html, or .md, and it is clear that /xxx does not meet this requirement.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is excepted, even with cleanUrl, users are required to add .md extension .

@wilsncc
Copy link
Copy Markdown

wilsncc commented May 25, 2025

I would really love to see this in VuePress, this is the one thing preventing me from using it.

@Mister-Hope
Copy link
Copy Markdown
Member Author

If @meteorlxy is happy to review it, then I am totally fine to refine this asap.

@Mister-Hope Mister-Hope marked this pull request as ready for review May 18, 2026 13:19
@Mister-Hope
Copy link
Copy Markdown
Member Author

@meteorlxy to support cleanurls, we must not rewrite /docs to /docs/, so a Webpack middleware is removed.

You should check why this is originaly introduced by you at an every early developing stage.

I check the commit history, and I can not see any clear motivation about this.

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.

[Bug report] add extra pages seems to have no effect [Feature request] CleanUrl

4 participants