When requesting /about, serve /about.html without redirect.
In config.js, have cleanURL: true by default.
When enabled, it will serve Clean URL like surge.sh or zeit's serve.
Some rule rewrites in the webpack-serve or koa part.
Don't have enough time, sorry.
😄 I was just about to open an issue on this, would be a great API! Btw, just as a quick add on, I noticed that having a path serve as a page and as a directory works only if a trailing slash is used:
.
├─ articles
│ ├─ README.md
│ └─ some-article.md
'/articles' => Returns only \
'/articles/some-article.html' => Returns all appropriate components for some-article, renders correctly
Perhaps this can be addressed with this issue as well...
@octref In favor of that, and we need to distinguish these two different scenarios:
/about/index.md, serve /about/index.html/about.md, serve /about.html@Gangwolf /articles isn't a semantic URL for /articles/REAMD.md, so please make sure that it URL ends with a slash.
@ulivz I think surge's rule for handling this is pretty straightforward: https://surge.sh/help/using-clean-urls-automatically
/foo/foo.html/foo.html isn't available/foo//foo/index.html, which can be either /foo/index.md or /foo/readme.md/foo//foo.html is available/foo/foo.html/foo.html is not available but /foo/index.html is, serve that, which can be either /foo/index.md or /foo/readme.md@Gangwolf
And for the request /articles, if /articles.md is available it should serve that. Otherwise it should redirect to /articles/ and serve the compiled html from /articles/[index|readme].md
@octref Awesome!
Maybe I need spend time researching whether all other mundane uses can also support such features, e.g. Github Pages / netlify.
Netlify also supports it https://www.netlify.com/docs/redirects/#trailing-slash
I do think GitHub support it too.
Cool, let's plan for it.
@ulivz @octref, thanks for clarifying 👍
Isn't there a drawback to this though? The redirects on the webhosts will cause a full page reload. This is not really what we want. Because the dev servers behavior will differ from the deployed sites behavior, and it won't be able to take advantage of client side routing.
Wouldn't it be better to generate a file structure for clean URLs when building? So that the site enables clean URLs by default, to take advantage of the client side routing.
@octref Hey, My opinion of the issue is same to you!
Would you please check my Pull Request and give me some suggestion?That's my solution but I'm not sure whethor the solution is elegant or not.
@meteorlxy
since the issue #720 has been closed, maybe we can have discussion here?
I also think url without trailing slash looks better. However, when you have these files:
/config.md/config/README.md/config and the /config/ should be different.However, if you have only one of them, maybe we really need redirect?I don't understand why it matters how the URL looks in devServer. You can set this up in prod easily if you wish.
IMHO, introducing this might incur unnecessary complexity in the URL resolving logic. I prefer to keep this simple and straightforward.
@Wangszzju
https://github.com/vuejs/vuepress/issues/603#issuecomment-398472571

@ycmjason
It's not just how the URL looks. It's how the devServer behaves.
For me, I prefer to organize subpages like this:
file -> dist -> url
/posts/foo.md -> /posts/foo.html -> /posts/foo
/posts/bar.md -> /posts/bar.html -> /posts/bar
/posts/baz.md -> /posts/baz.html -> /posts/baz
But now when I request /posts/foo on devServer, it redirects to /posts/foo/ and try to serve /posts/foo/index.html. That causes 404 and is inconsistent with my prod server.
If I organize my file like this:
/posts/foo/index.md
/posts/bar/index.md
/posts/baz/index.md
It at least works on devServer, but now I end up with URL with ugly trailing slashes.
FWIW, Firebase supports this too through the cleanUrls setting: https://firebase.google.com/docs/hosting/full-config#cleanurls
It would be great to have the dev server support “clean URL” behavior as available on all these hosting platforms.
Before actually starting to support this feature, I created a PR: feat($core): redirects for clean urls as a transition solution.
Fixed.
Most helpful comment
@ulivz I think surge's rule for handling this is pretty straightforward: https://surge.sh/help/using-clean-urls-automatically
For request
/foo/foo.html/foo.htmlisn't available/foo//foo/index.html, which can be either/foo/index.mdor/foo/readme.mdFor request
/foo//foo.htmlis available/foo/foo.html/foo.htmlis not available but/foo/index.htmlis, serve that, which can be either/foo/index.mdor/foo/readme.md