Reviewed the links provided by @holyjak, but still struggling with getting the query parameters. Here is the snipped I am dealing with:
:will-enter (fn [app route-params]
(log/info "Will enter ResetPwd" route-params)
(log/info "JS params" js/location.search)
(dr/route-immediate [:component/id :resetpwd]))
When I go to <http://localhost:3000/resetpwd?k=blah>
The JS printout looks like this:
INFO [bbuptop.ui.user-auth:350] - Will enter ResetPwd {}
INFO [bbuptop.ui.user-auth:351] - JS params ?k=blah
Do I need to set the route-params
somewhere?As I mentioned before, Fulcro routing is not connected to the URL in any way (though it is designed to work with it). If you go to /some/url, nothing happens in Fulcro routing until you write some code that react to that url and calls one of the route functions (as the RAD html5 routing does).
So you need what you described - look at the url and js/location.search
, parse it, then call fulcro routing.
It is the fulcro routing url->route
you are interested in. What is special about this impl is that it takes clj params maps and encodes that as a transit string so you end up with a single , unreadable param. You might not want that.
https://fulcro-community.github.io/main/awesome-fulcro/README.html links to @codonnell’s https://chrisodonnell.dev/posts/giftlist/routing/ which > use https://github.com/clj-commons/pushy, which wraps the HTML5 history API, and fulcro’s http://book.fulcrologic.com/#_dynamic_router to implement routing.
@holyjak, OK, so far so good, I think I implemented mostly everything, the back button works, and entering the URL in the browser bar works. The only thing I am still wondering about, is the the will-enter (fn [app route-params] ....
, where does the fn
pick up the route-params
, I should be able to set it somehow?
Those are the ones you pass to change-route
@holyjak, this solves my problem, thank you ...
@lgessler in :will-enter
in the desfc
block, you can read the params from JavaScript by reading the js/location.search
parameter. Then you can parse the params string using https://github.com/fulcrologic/fulcro-rad/blob/d30b318c75b2938555ff12d617b62c21ba041957/src/main/com/fulcrologic/rad/routing/html5_history.cljc#L37 function and then you can use the params.
Unfortunately, this does not seem right. The https://github.com/fulcrologic/fulcro-rad/blob/develop/src/main/com/fulcrologic/rad/routing/html5_history.cljc is probably the right solution to use, but I have not been able to figure it out.