Fork me on GitHub
#reitit
<
2022-10-19
>
aaron5110:10:55

I’ve written this function a few times in different projects — is there a built-in way to do this? Could I send a PR?

(defn path
  "Generate a path from the router"
  ([router name] (path router name nil nil))
  ([router name path-args] (path router name path-args nil))
  ([router name path-args query-args]
   (let [route (reitit/match-by-name! router name path-args)]
     (assert route (str "Missing route " (str name)))
     (reitit/match->path route query-args))))

valerauko12:10:51

in reitit.frontend.history it's called href https://github.com/metosin/reitit/blob/43e1a520d60aefa6bd7c67316b92f170c1e6d447/modules/reitit-frontend/src/reitit/frontend/history.cljs#L174-L181 so if you do send a pr it might be a good idea to use href as a name?

aaron5114:10:11

Nice :) I am using it server-side, so maybe it should be cljc?

aaron5118:10:51

(Our implementation also raises if there’s no route for the given name)

aaron5110:10:45

Also maybe there’s something better to raise than AssertionError