reitit 2025-05-08

hello! Is there a recommended way to do a catchall route for SPA app routing?

(ring/router
   [["/api"
     {:middleware []}
     ["/users/:user-id" {:get get-user-handler}]
     ["/items" {:post create-item-handler}]]
    ["/*" {:get {:handler spa-index-handler}}]]
   {:data {:muuntaja m/instance
           :middleware [parameters/parameters-middleware 
                        muuntaja/format-negotiate-middleware
                        muuntaja/format-response-middleware
                        muuntaja/format-request-middleware
                        #(resource/wrap-resource % "public")
                        content-type/wrap-content-type 
                        not-modified/wrap-not-modified]}})

this is giving me conflicting route exception. is there a way to get around that, or a different pattern i should use?

im doing a similar app to https://clojurians.slack.com/archives/C7YF1SBT3/p1624542943102900, where I have reitit routes on both the server side, and the clientside. and don't want to repeat all my routes on both.

I just stuck :conflicting true on /api and /* and we'll see if that works.

Put the routes in CLJC file and refer to them from either side, then you don’t need to repeat anything.

I do that and I don’t even use Reitit in the backend (I use Pedestal), so the routes go through a small conversion. In your case, you should be able to reuse them without too much work-

interesting, i will try that

for people searching: this example was helpful for me. having TWO routers, one being the backup router. https://github.com/metosin/example-project/blob/92aaeef26483ba93cd6b5faa89eaeba3911d50fc/src/clj/backend/routes.clj#L100

✅ 1