Skip to content

Commit

Permalink
Ensure a single trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
zampino committed Dec 12, 2023
1 parent 115f8f6 commit 11d08bc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/nextjournal/clerk/render.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -750,18 +750,18 @@
(when-not (ignore-anchor-click? e url)
(.preventDefault e)
(let [path (.-pathname url)
edn-path (str path
(when (str/ends-with? path "/") "index")
".edn")]
(js/console.log "pathname" path "path to EDN" edn-path)
edn-path (str path (when (str/ends-with? path "/") "index") ".edn")]
(-> (js/fetch edn-path)
(.then (fn [r]
(if (.-ok r)
(.text r)
(throw (ex-info "Not Found" {:response r})))))
(.then (fn [edn]
(set-state! {:doc (read-string edn)})
(.pushState js/history #js {} "" (str path "/")))) ;; 👈 trailing slash is needed to make relative paths work
(.pushState js/history #js {} ""
(cond-> path
(not (str/ends-with? path "/"))
(str "/"))))) ;; trailing slash is needed to make relative paths work
(.catch (fn [e] (js/console.error "Fetch failed" e ))))))))

(defn setup-router! [state]
Expand Down

0 comments on commit 11d08bc

Please sign in to comment.