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

fix: handle cleanUrls with subfolders when using a trailing slash #1575

Merged

Conversation

rigor789
Copy link
Contributor

@rigor789 rigor789 commented Nov 3, 2022

The main change is that when using with-subfolders the page should always be generated as /page_name.md -> /page_name_index.md (since it's generated as /page_name/index.html

On the client side, whether or not there's a trailing slash, it resolves to the _index file when using cleanUrls.with-subfolders. Still need to check if this works/breaks without-subfolders.

Also need to clean up, there's duplicated logic now in various places.

There is one thing to note about relative links, since they are resolved by the browser, they look for the last / in the url, and resolve them relative to that. So depending on how the host redirects and handles trailing slashes, relative URLs might break.

For example, /pageA.md would produce the following files:

mode file path
disabled /pageA.html
without-subfolders /pageA.html
with-subfolders /pageA/index.html

And these depending on the hosting can end up with the following urls in the browser (excluding what vue-router would normally produce for internal links):

/pageA.html /pageA/index.html
/pageA /pageA
/pageA/ /pageA/
/pageA.html /pageA/index.html

And depending on the url, a ./pageB link would resolve like this

URL Resolved
/pageA ✅ /pageB
/pageA/ ❌ /pageA/pageB
/pageA.html ✅ /pageB
/pageA/index.html ❌ /pageA/pageB

So depending on the hosting, relative URLs might break, even with cleanUrls disabled.

/cc @brc-dd

fixes #1442.

@rigor789 rigor789 marked this pull request as ready for review November 3, 2022 17:36
@brc-dd brc-dd self-assigned this Nov 11, 2022
@brc-dd brc-dd force-pushed the feat/clean-urls-with-subfolders-trailing-slash branch from 07a4fcd to 3c64778 Compare December 21, 2022 09:42
@brc-dd
Copy link
Member

brc-dd commented Dec 21, 2022

Dev appears to be broken after this if we have some path like /foo/index.md (without cleanUrls set).

@brc-dd brc-dd marked this pull request as draft December 21, 2022 10:05
@rigor789
Copy link
Contributor Author

Dev appears to be broken after this if we have some path like /foo/index.md (without cleanUrls set).

This seems to fix it:
image

What is the expected behavior when you have cleanUrls enabled, and have a /guide/markdown.md - then open the following urls:

  • /guide/markdown
  • /guide/markdown/

(note, I'll push up the above change, just wanted to clarify if it's working as intended, or we need additional logic somewhere)

@brc-dd
Copy link
Member

brc-dd commented Dec 21, 2022

/guide/markdown --> /guide/markdown.md

/guide/markdown/ --> /guide/markdown.md or /guide/markdown/index.md whichever exists if (cleanUrls === 'with-subfolders') else /guide/markdown/index.md

@rigor789
Copy link
Contributor Author

/guide/markdown --> /guide/markdown.md

/guide/markdown/ --> /guide/markdown.md or /guide/markdown/index.md whichever exists if (cleanUrls === 'with-subfolders') else /guide/markdown/index.md

Ok, then we need some additional logic, with the above it works as before for the most part in dev mode:

  • /guide/markdown -> /guide/markdown.md
  • /guide/markdown/ -> /guide/markdown/index.md

@brc-dd
Copy link
Member

brc-dd commented Dec 21, 2022

Yeah, push it anyway though. If everything is working for the other two options and we can fix build properly for with-subfolders + trailing-slash, then that's fair too.

@brc-dd brc-dd marked this pull request as ready for review December 22, 2022 08:49
@brc-dd brc-dd merged commit 195d867 into vuejs:main Dec 22, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2023
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 this pull request may close these issues.

CleanUrls with with-subfolders/without-subfolders fails lookup from __VP_HASH_MAP__ upon trailing slash
2 participants