Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable 'clean url' in client router #219

Closed
jaalt007 opened this issue Feb 3, 2021 · 4 comments · Fixed by #856
Closed

Configurable 'clean url' in client router #219

jaalt007 opened this issue Feb 3, 2021 · 4 comments · Fixed by #856

Comments

@jaalt007
Copy link

jaalt007 commented Feb 3, 2021

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

In production it may be desirable to strip the .html extension in urls. Of course this isn't a direct concern of vitepress, and typically static hosts provide a turnkey setting to do this e.g; https://vercel.com/docs/configuration#project/clean-urls

However the client side router will append .html to the history push state when navigating:

This will result in an extra server redirects when e.g. sharing urls, doing hard reloads; that ideally could be avoided.

Describe the solution you'd like

To be able to configure this .html appending behaviour on the client router :)

@kiaking
Copy link
Member

kiaking commented Feb 10, 2021

Thanks for the feedback! Interesting. Sounds nice, but the concern would be it might be misleading for people who are not using advanced hosting such as Vercel. If we have option like cleanUrl: true, then people might think VitePress is going to generate clean url directly structure.

/index.html
/guide/getting-started/index.html

I guess we need to be extra careful when designing spec if we were to add this feature 🤔

@GamearooCodes
Copy link

This would be a nice feature to be able to have it as /about instead of /about.html

@talawahtech
Copy link

FYI the issue mentioned by @jalt007 happens with Cloudflare Pages, but unlike vercel, there is no way to run it off. It also causes web analytics numbers to be duplicated.

https://developers.cloudflare.com/pages/platform/serving-pages#route-matching

@mythz
Copy link

mythz commented Oct 16, 2021

Not being able to configure usage of Clean URLs is a big blocker that has already cost vue/vitepress high profile users like tailwind's author who ultimately went with Next.js for tailwind's docs:

137580889-17f10368-dbd8-4d7e-b203-c424898a7df3

It would've also been a blocker for us to be able to use vue/vitepress but managed to create a hack to remove the offending client router LOC that auto appends '.html' suffixes:

{
  "scripts": {
    "postinstall": "node -e \"var fs=require('fs'),js='node_modules/vitepress/dist/client/app/router.js';fs.writeFileSync(js,fs.readFileSync(js,'utf8').replace(\\\"url.pathname += '.html';\\\",''))\""
  }
}

This is enough for us to continue with evaluation of vitepress but obviously we'd feel more confident if this popular SSG feature was a supported option.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants