vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
11.33k stars 1.83k forks source link

rewrite URL got 404 in build mode #3766

Closed hyunicode closed 2 weeks ago

hyunicode commented 3 weeks ago

Describe the bug

my rewrite rules are as follow, it works fine on dev mode, but url is not automatically converted on build mode. I can change the url manually and it does work, I am looking for a more efficient way. rewrites: { 'src/components/:pkg/docs/(.*)': ':pkg/index.md', },

Reproduction

rewrites: { 'src/components/:pkg/docs/(.*)': ':pkg/index.md', },

npm run docs:build ans see if the target url automatically converted.

Expected behavior

url behaviour should be the same between build mode and dev mode

System Info

System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 1.29 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.12.1 - /usr/local/bin/node
    Yarn: 1.22.21 - /usr/local/bin/yarn
    npm: 10.5.0 - /usr/local/bin/npm
    pnpm: 8.14.0 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 123.0.6312.107
    Edge: 123.0.2420.81
    Safari: 17.4.1
  npmPackages:
    vitepress: ^1.0.2 => 1.0.2

Additional context

Some related discussions... but I didn't find a solution https://github.com/vuejs/vitepress/pull/1798 https://github.com/vuejs/vitepress/issues/2276 https://github.com/vuejs/vitepress/pull/2301 https://github.com/vuejs/vitepress/issues/3062 https://github.com/vuejs/vitepress/discussions/3198

Validations

brc-dd commented 2 weeks ago

Please share a reproducible example in form of a github repo or using https://vitepress.new

hyunicode commented 2 weeks ago

https://github.com/hyunicode/vitepress_demo

  1. git clone git@github.com:hyunicode/vitepress_demo.git
  2. yarn
  3. yarn docs:build
  4. yarn docs:preview
  5. click nav 'click here'

and you can see the '404'

brc-dd commented 2 weeks ago

It's expected behavior. You need to reference using final URLs. Make it { text: 'click here', link: '/examples/' }.

hyunicode commented 2 weeks ago

It's expected behavior. You need to reference using final URLs. Make it { text: 'click here', link: '/examples/' }.

In my opinion, the behavior in dev mode should be consistent with that in prod mode. Maybe all 404 can remind developers to modify their rewrite rules