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
Converting Luminus default (~Secretary) to Accountant #52
Comments
Your setup looks fine at a glance to me. I normally include a call to |
I get
This doesn't sound much like an accountant problem, except for the fact that I'm just replacing the |
I'm afraid I'm not sure. It sounds like you've got a component that's appearing as |
I've narrowed the problem down, though I don't know what's causing it. Although I have all those secretary/defroutes in place, but they aren't functioning. The session is supposed to be getting pages sent to its :page value but that isn't happening; hence, reagent is being told to render [nil] because there is no :page value on the session. Using the repl I can eventually get it to render by executing (secretary/dispatch! "/applicant"). However, after some trial and error, I can verify that (accountant/dispatch-current!) fails to implement (secretary/dispatch! path). In otherwords, given a valid path, I can in the repl run (secretary/dispatch! path) and it works, but it doesn't happen with trying to navigate there by clicking and expecting accountant to do it. I have no explanation, since this println is working:
In otherwords, clicking a link causes the println to fire, but to actually get the page to render I have to manually call |
That is extremely unusual. Do you have something else in your application that could be controlling the History? |
I found the problem. My secretary setup specifies
In other words, the path accountant receives has the hash in it, but the path secretary expects does not. What is the recommended setup as far as prefixes for an SPA? |
To be honest, I don't know - I've never developed on an application with prefixed URLs like that. Does setting the prefix as "#/" change anything? |
Okay; I have it fully functional, probably as intended, by removing the config prefix and having all routes go somewhere without a #. I have a question, though, about the philosophy of accountant's approach to SPAs; it's probably something I have fundamentally wrong. If I click around the app I navigate fine; but if ever I try reloading a page, or if I follow a link someone sends me from a page within the app, it will always come back with a 404 because the server doesn't know the path (only the js app knows the path). How should this be resolved? |
I think the easiest solution is to update the server code to constantly return the page (if it is not a resource). Something along the line of: (require '[ring.middleware.resource :as r])
(defn handler [req]
((r/wrap-resource
(constantly
{:status 200
:body (render home.html)})
"/")
req)) If SSR is in the scope I imagine you need to do something more ambitious and share the routing between the client/server. |
Ah; I see. I'll use a catch-all for get requests, and make sure my ajax responses are on different paths. Thanks! |
@iku000888 beat me to it but I’d have said the same thing. Just whitelist the paths server-side. |
In spirit, I did something similar (hopefully without unforeseen consequences), which seemed the simplest given the Luminus setup already present:
|
You’ll want to explicitly whitelist your server routes just to get sane 404s from your API endpoints in my experience. |
Ah; respecting your experience, I went ahead and used the "whitelist" approach. |
I have a luminus setup for various apps. On one, I now need Accountant's ability to link internally (e.g. as an event handler) without causing a browser refresh. I'm a bit lost in getting the setup working; here's a gist with my existing setup and my attempt to get accountant working. Help would be much appreciated.
https://gist.github.com/WorldsEndless/43c8efc6d4db1ff684d9260fe22ddfc7
The text was updated successfully, but these errors were encountered: