docsify icon indicating copy to clipboard operation
docsify copied to clipboard

URLs 404 when given a trailing slash /

Open Giovanni-Mattucci opened this issue 5 years ago • 15 comments

Bug Report

Steps to reproduce

Go to any page path and add a trailing slash / to the end Example: /#/hello/

What is current behaviour

The page apth /#/hello/ will 404

What is the expected behaviour

That the page requested is shown and works the same as /#/hello

Other relevant information

No

  • [x] Bug does still occur when all/other plugins are disabled?

  • Your OS: Windows 10

  • Node.js version: 8.11.3

  • npm/yarn version: 5.6.0

  • Browser version: Chrome Version 79.0.3945.130

  • Docsify version: latest unpkg (4.10.2)

  • Docsify plugins: search

Giovanni-Mattucci avatar Feb 11 '20 15:02 Giovanni-Mattucci

Well,

/#/hello/ should not behave like /#/hello

Because, /#/hello means rendering /hello.md file.
according to your proposal, rendering /#/hello/ -> /hello.md will break the working of rendering the content of dir rendering.

/#/hello/ mean hello is a directory and docsify will look for homepage in it which is README.md by default. changing the behavior of docsify to support /#/hello/ -> /hello.md will never able to render directory content.

if you have any other proposal to change the behavior, please comment. !!

cc @docsifyjs/core @trusktr @jthegedus Any proposal you guys want to give !!!

anikethsaha avatar Feb 13 '20 21:02 anikethsaha

I think most websites on the internet with modern history routing render /hello/ and /hello as the same thing. This can cause Docsify sites to perform differently to what is expected by the average user.

I am not very familiar with routing modes and their differences, but maybe this is expected behaviour for hash mode routing in that you must be explicit with your trailing slash?

I will think on a proposal for a day.

jthegedus avatar Feb 14 '20 00:02 jthegedus

In my opinion, I agree with @anikethsaha . this is the URI and URL issue. Normally, when u visit the /hello/ means u wanna visit the /hello/index.html or /hello/default.html. so, as for docsify, when you visit #/hello/ means u wanna visit #/hello/idk.md instead of the hello.md.

Koooooo-7 avatar Feb 14 '20 04:02 Koooooo-7

this is the URI and URL issue. Normally, when u visit the /hello/ means u wanna visit the /hello/index.html or /hello/default.html. so, as for docsify, when you visit #/hello/ means u wanna visit #/hello/idk.md instead of the hello.md.

Yeahh

I will think on a proposal for a day.

yea sure..

anikethsaha avatar Feb 14 '20 07:02 anikethsaha

My initial comment was more questioning the difference between hash and history and if this was the cause.

Given 3 files:

  • hello.md
  • hello/homepage.md
  • hello/something.md

I agree that

/hello             -> /hello.md
/hello/            -> /hello/homepage.md
/hello/something   -> /hello/something.md

Where we can improve is what we do when there is no homepage.md in a path. Surely there's a better practice then just providing a 404 for this case?

Given 2 files:

  • hello.md
  • hello/something.md

The 404 seems wrong.

/hello             -> /hello.md
/hello/            -> 404
/hello/something   -> /hello/something.md

If we know there is not a homepage.md file/route, surely we can be more forgiving and redirect the user back to /hello.md, becoming:

/hello             -> /hello.md
/hello/            -> /hello.md (no homepage.md found so redirected to next pattern match of URL) 
/hello/something   -> /hello/something.md

I am not too fussed on the outcome here, though reading this issue reminded me of my first time using Docsify where I wished I didn't need to create intermediary index pages for all my routes. I just wanted to redirect back to another page of my liking that I knew existed, or the next match in the URL pattern.

jthegedus avatar Feb 14 '20 08:02 jthegedus

@jthegedus I am +1 for the proposal you mentioned.

can you submit a PR with that. I am planning to do a release by this month. so It will be great if we ship this fix with it

anikethsaha avatar Feb 14 '20 15:02 anikethsaha

@jthegedus your solution would make things behave more as expected, so looking forward to that :)

Giovanni-Mattucci avatar Feb 14 '20 15:02 Giovanni-Mattucci

Agree with @jthegedus proposal, except to make it index.md instead of homepage.md

joetidee avatar Mar 06 '20 10:03 joetidee

cc @jthegedus any update on this ?

anikethsaha avatar May 14 '20 16:05 anikethsaha

I have not started work on this. Will give it a crack over the weekend. Help is welcome should anyone else find they have the time.

jthegedus avatar May 15 '20 02:05 jthegedus

In GitHub Pages, isn't README.md is the index.html or default.html behavior? I mean it would make more sense to have a README.md as a convention.

kosperera avatar Jun 08 '20 18:06 kosperera

I think we can default to README.md by matter of the existing conventions, and we can also fall back to index.md if README.md is not found. Thoughts? *#!/*JoePea

On Mon, Jun 8, 2020 at 11:42 AM Kosala Nuwan Perera < [email protected]> wrote:

In GitHub Pages, isn't README.md is the index.html or default.html behavior? I mean it would make more sense to have a README.md as a convention.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/docsifyjs/docsify/issues/1018#issuecomment-640803482, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACIVTW5D6WZPWFIKE3S7ADRVUWIXANCNFSM4KTDGRKQ .

trusktr avatar Jun 08 '20 19:06 trusktr

@trusktr Of course index.md would do. But, I would expect the sub-folders must be treated similarly to the root. I think it should behave the same way how Docsify currently treating the docs/ root, i.e. a mixture of README.md and _coverpage.md. I believe these are the defaults of Docsify. Unless otherwise, the sub-folder itself is another Docsify-enabled site on its own.

kosperera avatar Jun 09 '20 10:06 kosperera

Whoa, I'm two years late to the party, but has this been resolved at all? It'd be terrific if example.org/hello/README was just the same as example.org/hello

443pablo avatar Nov 04 '22 01:11 443pablo

This is is annoying for sure. We need to handle trailing slashes properly.

Additionally, we have high-level things to improve in Docsify:

  • first of all, we should not have two totally separate renderers for client vs SSR (duplicated logic, error prone keeping changes in sync)
  • we should not have duplicate logic across our two routers (also error prone keeping changes in sync, leading to inconsistency)

trusktr avatar Jan 23 '23 02:01 trusktr