I want to share one thought of mine about dynamic routing: The most mind-blowing simple but fully functional routing solution (based on window.history) I have seen so far is one written in ReasonML: Description Code
The secret sauce is just to split the URL (by /) into a list (ReasonML tail-recursive version of an array, or what in Rust is called Vec) of path segments, than the user of the api can recursively pattern match on that list to do his thing.
I am new to Rust, but it seems to me Rust pattern matching should also allow to do something like that.
The text was updated successfully, but these errors were encountered:
Looks great - that's the best routing approach I've seen. The issue that's driving the lack of dynamic routes is related to lifetimes, and where/how to store the popstate-listening closures so we can remove them when adding new ones... The temporary workaround is to create one closure at the start, and never detach it. Need to solve this first. (I think the relevant part of the code you linked is the external removeEventListener : part.)
yes, at the example, in the didMount app-level life cycle hook, a closure gets registered with the route map and how it has to be processed. And still in that didMount hook, the removeEventListener stuff gets wired up to be run in a closure at component unmount, at: self.onUnmount(() => ReasonReact.Router.unwatchUrl(watcherID))
Added partial dynamic routing in latest commit. See todomvc example. Still need to specify landing page routing, same syntax as before, but now you can push to pages not included in it. Must pass app state down to routing messages, which adds verbosity, but no longer need to recursively call update.
What do y'all think? Any thoughts on dynamic landing pages? Think programmatically setting up the HashMap is enough, or do we need a regex/recursive-pattern-match approach? Maybe I should change the API to be more like that ReasonMl example; it's nicer.
Interested in the group, but won't necessarily be avail Thu.
Latest commit has a complete rework of the routing system; it's now like the ReasonML example. I expect this API to stay the same; it's about as simple as it can get. Might have some changes to make internally re how hash and search are handled.