-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
✨ Feature - Optional hash-based routing #50
Conversation
✅ Deploy Preview for elm-land canceled.
|
936a082
to
3ef1ad4
Compare
3ef1ad4
to
72d45bb
Compare
d0c93c0
to
11cdf19
Compare
11cdf19
to
a6aff8a
Compare
I think that apart from the terrible example this is now in a spot that I'm happy enough with it to start getting feedback. Things I am particularly wondering are:
I had an idea for a silly Vite plugin/server trick where enabling hash routing would send a message to the browser Vite client and trigger an update to window.location to add/remove the hash so the app stays on the same logical page, but decided to table it in the interest of simplicity for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to merge this in, and take care of any changes that need to be made to get it working with the new Route.Path implementation – this will be released with v0.18.0 🚀
Thanks again, @MattCheely !
Problem
Hash routing isn't popular in modern frameworks, but there are scenarios where it's quite useful, most notably when the desired (or only) hosting stack is a very simple one that only serves static files (e.g. github pages, S3, etc)
Solution
This PR creates a new config setting:
app.options.useHashRouting
that will cause the generated routing modules to parse the URL fragment as if it is the path, query and fragment. Theurl
property on route objects still reflects the real browser URL, however.Notes
This is currently still a work-in-progress, but I wanted to share the basic approach for feedback before I continue to polish it. There are a number of failing tests that need to be resolved,the example is not a useful example,and of course probably some code to clean up in a few places.A brief overview of the changes:
A new
HashRouting
module is generated that provides the transformation from the browser URL to aUrl
value appropriate for hash-based routing. This gets it's own module because it ends up being referenced in several places:fromUrl
matches against segments in the browser URL hashfromUrl
matches against query-like strings in the URL hashRoute
' record'shash
field is taken from the hash within the hash (yo dawg)I initially considered updating just
Route
, butRoute.Path.fromUrl
is called directly byelm-land
in several places, and is useful on it's own for users. IMO, it would be strange and confusing ifRoute.Path
andRoute.Query
did something different from route when imported and used directly.One alternate option might be to move it all into a single module, although I having the
HashRouting
module separate might have some value in documenting how to set up hash-triggered redirects in the event that an app wants to transition from hash routing to push-state routing.Did I say this overview would be brief? 😅