Fork me on GitHub
#fulcro
<
2021-06-13
>
Timofey Sitnikov02:06:29

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 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?

Jakub Holý (HolyJak)16:06:37

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).

Jakub Holý (HolyJak)16:06:45

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.

Timofey Sitnikov09:06:39

@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?

Jakub Holý (HolyJak)14:06:46

Those are the ones you pass to change-route

😀 3
Timofey Sitnikov10:06:07

@holyjak, this solves my problem, thank you ...

❤️ 3
Timofey Sitnikov02:06:27

@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.

Timofey Sitnikov02:06:51

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.