-
Notifications
You must be signed in to change notification settings - Fork 71
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
Allow Hash-Based Routing #425
Comments
Hey @franz-sw ! Thanks for this interesting discussion. BTW, if you're not aware, the 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. |
Thanks for the response @bitspittle, |
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:
Client-Side Handling: Everything after the # in the URL (the hash fragment) is not sent to the server. It is only accessible and handled by the browser. This means the server only sees http://example.com/, and it always serves the same HTML file, typically index.html of your SPA.
JavaScript Listens to Hash Changes: The JavaScript running on the page listens for changes to the hash fragment. When a user navigates to a different hash fragment, the JavaScript updates the page's content accordingly, without a full page reload.
Browser History: Modern browsers treat each unique hash fragment as a separate history entry, enabling the use of the browser's back and forward buttons, similar to traditional multi-page websites.
Advantages for SPA Hosting
Simplified Server Configuration: Since the server only needs to serve the main index.html file regardless of the hash fragment, there's no need for complex server-side URL rewriting. This makes hash-based routing highly compatible with a wide range of hosting environments, including basic static file servers.
Fallback for Legacy Browsers: Hash-based routing is supported by all browsers, including older ones that don't support the HTML5 History API.
Instant Routing Decisions: Since routing decisions are made client-side based on the hash, it can lead to faster perceived navigation performance.
Ease of Deployment: Deployment on servers without support for clean URLs (path-based routing) is straightforward, as you don't rely on server-side logic to handle different routes.
The text was updated successfully, but these errors were encountered: