reitit

2025-05-08T19:36:58.619409Z

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]}})

2025-05-08T19:37:56.880279Z

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

2025-05-08T19:38:58.611739Z

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.

2025-05-08T19:39:55.065949Z

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

simongray 2025-05-09T07:00:38.254209Z

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

simongray 2025-05-09T07:01:51.174469Z

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-

2025-05-09T15:11:37.488579Z

interesting, i will try that

2025-05-09T20:02:26.370889Z

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