varabyte / kobweb

A modern framework for full stack web apps in Kotlin, built upon Compose HTML
https://kobweb.varabyte.com
Apache License 2.0
1.58k stars 71 forks source link

Allow Hash-Based Routing #425

Open franz-sw opened 10 months ago

franz-sw commented 10 months ago

As my SPA hosting provider doesnt sopport URL rewriting (no permission for .htaccess rewrite engine) user always get an 404 error if they navigate from outside to any page of my site ( e.g. http://example.com/page would not open http://example.com/page.html , instead it throws an 404 ) For me Hash-Based Routing (explained below) seems to also be an advantage for other users as it makes everything lighter and only an index.html is needed. As a workaround for now i am rename all my route from e.g. http://example.com/page to http://example.com/page/index.html which works, but I would appreciate it if you consider this suggestion.

Explanation of Hash-Based Routing

In hash-based routing, the URL looks something like this: http://example.com/#/page. Here, /page is the hash fragment. The key aspects of hash-based routing include:

Advantages for SPA Hosting

bitspittle commented 10 months ago

Hey @franz-sw ! Thanks for this interesting discussion.

BTW, if you're not aware, the kobweb block does have a cleanUrls property which defaults to true. You can set it to false (kobweb { cleanUrls.set(false) }) and then that will require people visit the page with ".html" on the end, which should be more consistent with what your server is forcing you to do.

To be upfront with you, I'm not planning on prioritizing hash-based routing. There's simply too much to do as is, and you are the first person who has asked for it. I will happily leave this comment up though so that other users may find it and chime in with their own thoughts.

One of the biggest advantages that Kobweb provides is SEO support. Creating one export per route is kind of Kobweb's secret sauce (as secret as an open source project can get I guess!). As far as I can tell, hash-based routing is not at all SEO friendly?

I appreciate it could be useful to be able to mimic clean URLs even with a web hosting service that doesn't support them, but at the moment I don't think complicating the codebase to support that use-case would be a good trade-off.

Especially, the standard definition of fragments for HTML is meant to relate to an element with some ID inside the document. Maybe I'm wrong about this, but I feel like hash-based routing is a case of using a feature in an unexpected way.

Finally, going through your advantages:

I'm sure this answer is disappointing but I hope you feel at least it was respectful and informative.

franz-sw commented 10 months ago

Thanks for the response @bitspittle, i am happy that Kobweb exists and the hint for the cleanUrls property is indeed very helpful for my use case.