Giter VIP home page Giter VIP logo

Comments (9)

prestancedesign avatar prestancedesign commented on June 18, 2024

Which routing lib do you use?

Here you can find an example how it's managed for the PingCRM demo with Reitit: https://github.com/prestancedesign/pingcrm-clojure/blob/88317da68a4fb7073dd1b936ab3c8749eeeb7036/src/clj/pingcrm/router.clj#L96-L97
And the custom 404 page: https://github.com/prestancedesign/pingcrm-clojure/blob/9505c33c27ac736e18aae6a0e97acd099c1fb3f0/src/clj/pingcrm/templates/404.clj

The live demo 404 page: https://inertia.prestance-design.com/jkjk

LMK, if it helps.

from inertia-clojure.

KaranAhlawat avatar KaranAhlawat commented on June 18, 2024

I'm using reitit-ring as my routing lib.

I tried what is used in ping-crm, but the problem is I have my 404 template as a Svelte component. Hence it requires the use of inertia/render function to tell Inertia to display it. That I haven't been able to figure out how to use with the create-default-handler.

from inertia-clojure.

prestancedesign avatar prestancedesign commented on June 18, 2024

OK, so you use Clojure for the back end and Svelte for the front end, right?

from inertia-clojure.

KaranAhlawat avatar KaranAhlawat commented on June 18, 2024

Yes, that would be correct. I can share the link of the repo if that would be helpful.

https://git.sr.ht/~korven/svelte-inertia

from inertia-clojure.

prestancedesign avatar prestancedesign commented on June 18, 2024

Does the 404 page have to be dynamic?

If not, I would use a static template like resources/404.html and set create-default-handler to point to this file in line 39 of your server.clj file: https://git.sr.ht/~korven/svelte-inertia/tree/master/item/server/inert/server.clj#L39:

(ring/create-default-handler
    {:not-found (constantly
                 {:status 404
                  :body (-> "404.html" io/resource io/file)})})

Does this solution suit for you?

from inertia-clojure.

KaranAhlawat avatar KaranAhlawat commented on June 18, 2024

That would work, in theory yes. But I'd rather have a Svelte component, just so I can integrate it with the global layout, just like other pages. Makes navigation easier. If there is no other way though, I suppose nothing to be done about it.

from inertia-clojure.

prestancedesign avatar prestancedesign commented on June 18, 2024

FYI, I just released a new version which keep now the http status code specified in the handler response.

So you can now update your default-handler with:

(defn default-handler
  "Render the Default component"
  [_]
  (-> (inertia/render :Default {:status 404})
      (assoc :status 404)))

Please, let me know if this answers your question.

from inertia-clojure.

KaranAhlawat avatar KaranAhlawat commented on June 18, 2024

That works perfectly! I really missed something so simple. Thanks for your time, it's a pleasure working with this library. Will be closing this now.

from inertia-clojure.

prestancedesign avatar prestancedesign commented on June 18, 2024

OK perfect, you're welcome!

I really missed something so simple.

A new release with some modifications was necessary to handle correctly and keep the status code so thanks for pointing it out: 6b1bb45

Do not hesitate to do a PR to add your repo on fullstack project example readme section when finished.

from inertia-clojure.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.