New release of Inertia-clojure v0.2.1, Clojure middleware for Inertia.js to build single-page apps, without building an API. https://github.com/prestancedesign/inertia-clojure This version supports History.pushState (query-string appended to URI), so the app state is loaded/restored even after direct access to a URL Props are now optional via multi-arity render function. Some demo examples updated
Oh yes of course, it's possible...this is even the core of Inertia.
All the logic (routing, sign in -> auth -> redirect, etc) remains managed by the back end.
Then handlers returning Inertia reponses take a front-end template (for each routes) in second arg:
(inertia/render :the-template-name props)
Eg. here :user-list
https://github.com/prestancedesign/reagent-inertia-reitit-integrant-fullstack/blob/main/src/usermanager/controllers/user.clj#L21
In fact, it is more of a component than a template. This is then used in the front end (whether with CLJS Reagent, etc or JS React, Vue) with the same component name with with the props passed in 3rd argument. See: https://github.com/prestancedesign/reagent-inertia-reitit-integrant-fullstack/blob/main/front/src/reagent/inertia.cljs#L31
Hope this is more clear. I am planning more documentation, and tutorial and I am currently making the official Inertia demo "PingCRM" http://demo.inertiajs.com who cover authentication, etc in Clojure / ClojureScript which I will put online soon. Do not hesitate if you have other questions and stay tuned. 😉
> (inertia/render :the-template-name props)
Ah ok. I didn't know the keyword meant template name. The example has just one template, (inertia/wrap-inertia routes template asset-version)
, and both routes have a different keyword but pass a map with a :title
key which is in the one template passed to inertia/wrap-inertia
> I didn't know the keyword meant template name. Yes, I must to add docstring too for more clarity.
Indeed, the template passed to the wrap-inertia middleware is the "root template". It is the container with the js, css, meta, etc. scripts as well as the <div id="app" data-page="JSON object props"
on which the front end components will be hooked.
Check: https://inertiajs.com/server-side-setup#root-template
Thanks for taking the time to explain this to me and for providing these links
Is it possible to use different templates for different routes?
No, this has not been necessary at the moment. Can you specify for which case you would like to have this possibility? Thx
Signed in versus signed out? If the user isn't signed in, redirect her to sign in. Once signed in, redirect her to the dashboard. Different templates for public and protected content?