vite
vite copied to clipboard
`serve`: with `base: '/docs/'`, should `/docs` work as `/docs/`?
Describe the bug
When run with vitepress dev docs --base /docs/
and visit /docs
route, it will be response with a message:
The server is configured with a public base URL of /docs/ - did you mean to visit [/docs/docs](http://localhost:3000/docs/docs) instead?
I would expect /docs
render same as /docs/
or just redirect to /docs/
instead.
Related https://github.com/vuejs/vitepress/issues/852
Reproduction
https://github.com/JounQin/test/tree/vitepress
System Info
System:
OS: macOS 13.0
CPU: (10) arm64 Apple M1 Max
Memory: 20.53 GB / 64.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.15.1 - ~/Library/Caches/fnm_multishells/50102_1656090482477/bin/node
Yarn: 1.22.19 - ~/Library/Caches/fnm_multishells/50102_1656090482477/bin/yarn
npm: 8.13.1 - ~/Library/Caches/fnm_multishells/50102_1656090482477/bin/npm
Browsers:
Chrome: 103.0.5060.53
Firefox: 101.0.1
Safari: 16.0
npmPackages:
@vitejs/plugin-react: ^1.3.2 => 1.3.2
vite: ^2.9.12 => 2.9.12
Used Package Manager
yarn
Logs
N/A
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
I think this is expected. /docs
is outside of /docs/
.
That said, IMHO changing the message to below would be friendly.
did you mean to visit [/docs/docs](http://localhost:3000/docs/docs) or [/docs/](http://localhost:3000/docs/) instead?
We now consider `` same as /
, what means http://localhost:3000
is exactly same as http://localhost:3000/
, the consistent behavior should be http://localhost:3000/docs
vshttp://localhost:3000/docs/
.
In URL spec, http://localhost:3000
is equivalent to http://localhost:3000/
, but http://localhost:3000/docs
is not equivalent to http://localhost:3000/docs/
.
new URL('http://localhost:3000').href === new URL('http://localhost:3000/').href // true
new URL('http://localhost:3000/docs').href === new URL('http://localhost:3000/docs/').href // false
https://url.spec.whatwg.org/#url-equivalence
Vite is not doing something special here.
As a user it is very common to visit /docs
instead of /docs/
just like `` vs /
, and the current behavior is meaningless for end user because there could never be a /docs
page? It's a UX issue.
It is a server configuration issue, if you want to have this behavior, add a server middleware to do a redirection or forwarding, maybe we can add an option to enable it in the dev server and also in the preview.
I configure my production servers when using some context/scope
instead root.
I understand that but it is confusing if /docs
returns the content of /docs/
.
I think it is ok to change the message.
Maybe it is not confusing if the redirect works after some seconds like <meta http-equiv="refresh" content="3;url=http://localhost:3000/docs/" />
.
It is a server configuration issue
Right, that's why it should 'fixed' in serve
command.
I understand that but it is confusing if /docs returns the content of /docs/.
My fix is just doing a redirect from /docs
to /docs/
, it should not be confusing?
Maybe it is not confusing if the redirect works after some seconds like
<meta http-equiv="refresh" content="3;url=http://localhost:3000/docs/" />
.
It's still meaningless for an end user to understand the difference between /docs/
and /docs
? Why should they care about that?
maybe we can add an option to enable it in the dev server and also in the preview
I believe that option is not very helpful? When would an end user expect /docs
results different from /docs/
when there can never be a /docs
page?
It's still meaningless for an end user to understand the difference between /docs/ and /docs? Why should they care about that?
I think it is not completely meaningless but I agree that a user does not need to care about it usually.
@sapphi-red I've just rebased #8772, please help to review, it should fix serve
and preview
at the same time.
I also encountered the same problem, after changing 'base', many links still can't be added...