diff --git a/src-contrib/electric_fiddle/main.cljc b/src-contrib/electric_fiddle/main.cljc index e929e97..9fbbddb 100644 --- a/src-contrib/electric_fiddle/main.cljc +++ b/src-contrib/electric_fiddle/main.cljc @@ -9,6 +9,15 @@ (e/defn NotFoundPage [& args] (e/client (dom/h1 (dom/text "Page not found: " (pr-str r/route))))) +(e/defn RedirectLegacyLinks! [link] + ;; Keep existing links working. + ;; Demos used to be identified by their fully qualified name - e.g. `hello-fiddle.fiddles/Hello + ;; They are now represented by an s-expression - e.g. `(electric-tutorial.demo-color/Color h s l) + (if (or (seq? link) (vector? link)) + link + (do (r/Navigate!. [(list link)]) + nil))) + (e/defn Main [ring-req] (e/server (binding [e/http-request ring-req] @@ -17,7 +26,7 @@ (r/router (r/HTML5-History.) (dom/pre (dom/text (pr-str r/route))) (let [route (or (ffirst r/route) `(Index)) ; route looks like {(f args) nil} or nil - [f & args] route] + [f & args] (RedirectLegacyLinks!. route)] (set! (.-title js/document) (str (some-> f name (str " – ")) "Electric Fiddle")) (case f `Index (Index.)