vuejs / vitepress

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

page render error #3832

Closed pclokcer closed 2 weeks ago

pclokcer commented 2 weeks ago

Describe the bug

if I use "/" character end of url, sidebar and middle page not working normally.

Reproduction

check this error https://stackblitz.com/edit/vite-9jamew

if you see error, add to <stackblitz test url>/en/test/ and enter. 404 page coming. but <stackblitz test url>/en/test like this working.

Expected behavior

need to work normally. 404 page is wrong.

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
    Memory: 2.38 GB / 15.87 GB
  Binaries:
    Node: 18.18.2 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - C:\Program Files\nodejs\yarn.CMD
    npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.6.1 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Edge: Chromium (122.0.2365.59)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    vitepress: ^1.1.3 => 1.1.3

Additional context

nginx conf like

server {
    gzip on;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    listen 80;
    server_name _;
    index index.html;

    location / {
        # content location
        root /app;

        # exact matches -> reverse clean urls -> folders -> not found
        try_files $uri $uri.html $uri/ =404;

        # non existent pages
        error_page 404 /404.html;

        # a folder without index.html raises 403 in this setup
        error_page 403 /404.html;

        # adjust caching headers
        # files in the assets folder have hashes filenames
        location ~* ^/assets/ {
            expires 1y;
            add_header Cache-Control "public, immutable";
        }
    }
}

Validations

brc-dd commented 2 weeks ago

Won't be fixed in dev. It works fine build + serve.

pclokcer commented 2 weeks ago

not working image

@brc-dd can you check like thiss ??


working image

working like this

brc-dd commented 2 weeks ago

You're using dev mode not prod site. Dev mode is correct. In prod you need to handle this in your server.

without proper routing, /en/test/ means there should be a file /en/test/index.md and /en/test means there should be a file /en/test.md

With cleanUrls: true, it should work fine on prod as long as your backend serves correct file. The provided nginx configuration in docs might be wrong though. It was contributed by external contributors and may not handle this case. PRs are welcome to update it.

brc-dd commented 2 weeks ago

dev will match prod behavior in next release. Regarding nginx config, I'll try to update the docs, but I don't have much experience with that.