I am trying to implement a settings page with a separate router. Are there any examples in the wild? I noticed I can't just use a router, because when I do, the query won't be merged and thus the sub-routed component won't have any of its queried (and loaded) data available in props.
There is a http://book.fulcrologic.com/#_code_splitting but I have no idea how one'd combine that with a router
How does Fulcro support a basic index route? I tried :route-segment [""]
but that doesn’t seem to work with the back button
core.cljs:159 ERROR [com.fulcrologic.fulcro.routing.dynamic-routing:636] - Could not find route targets for new-route []
You can't give it an empty route segment. You have to put something there. You can then give app/fulcro-app
the key :client-did-mount
which takes a function. I have (fn [app] (hist5/restore-route! app ui/LandingPage {}))
if you want a “/” route you do that in your own function to translate between what you think of as a URL and the actual target…just like you would in a normal web serving env…`/` never names a resource. It’s a directory. So, if you were translating from a URL of “/” you’d have a fn in between URL and dr that would “alias” /
to mean something like ["index"]
nesting routers is supported...not sure what you’re doing that is confusing you. You have to compose queries and initial state (though defrouter
does that for you for a router itself). I think the book itself shows such a nesting, doesn’t it?
It does indeed, and the helpful code is confusingly under "http://book.fulcrologic.com/#_setting_the_route_early" but yes, it works now 🙂
It's working now. Thanks.
I've been able to get mutations to alter behavior within a single component, but now I need set up an :onClick
mutation in some component X that changes some part of the state in another component Y. Anyone know where I can get more info on that? I'm probably going to start by rereading section 9 in the book.
That's what I suspected, but initial attempts weren't working. I will look into this, thank you!
From a client mutation you have the whole of app state. Start off with swap!->
[com.fulcrologic.fulcro.algorithms.normalized-state :refer [swap!->]]
, and do assoc-in
or call st->st* functions.Per http://book.fulcrologic.com/#_defining_remote_errors, I'm trying to handle server error responses, e.g. 401 responses. I have a fallback mutation on my transactions (e.g load!
) which I do see is being called, however the params :status-code
passed to this fallback mutation is 500, not 401 (which is the HTTP response code returned by the server). This is v3.4.2-1. What am I doing wrong? What do I need to do so that :status-code
matches the HTTP response code?
@tvaughan you might not be doing anything wrong…it could just be a mistake in the middleware copying the status code. I would not, in general, use status codes for error handling in Fulcro. Period. Assume a non-200 is a bug or network failure. Error handling makes a lot more sense to do as proper mutation return values.
this is different than what you might be used to from the REST world, but this is a different beast. It’s more like remote method invocation…an error means something went horribly wrong with the comm-layer (or a bug happened) such that the mutation was simply not able to even respond properly.
however, I do think the “raw” response is still in env
, so look deeper into what you got
> I do think the “raw” response is still in `env` A quick scan and I don't see it. Will continue to look. I don't follow that HTTP responses shouldn't be used to detect "errors." There could be a lot of things in front of a remote resolver or mutation that could intercept a request and send a response. Even in the RPC over HTTP world response codes aren't ignored. I'll see what sort of work arounds I can come up with. Thanks for the quick response!
:status-text
is Unauthorized. Using this seems to work
Any advice on getting rid of this warning?
core.cljs:159 WARN [com.fulcrologic.fulcro.ui-state-machines:215] - Attempt to get an ASM path [:com.fulcrologic.fulcro.ui-state-machines/local-storage :path-segment] for a state machine that is not in Fulcro state. ASM ID: :app.client/Router
#error {:message "", :data {}}
I found some related questions here, https://clojurians-log.clojureverse.org/fulcro/2020-02-14 - but I have dr/change-route!
in client-will-mount
and dr/initialize!
in my app start.