From e42c309144f86d03e6887983d0462800638733dd Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Thu, 23 Aug 2018 09:54:36 +0300 Subject: [PATCH] Read query string in HTML5 router --- examples/frontend/project.clj | 3 ++- examples/frontend/resources/public/index.html | 2 +- examples/frontend/src/backend/server.clj | 11 +++++++++++ .../reitit-frontend/src/reitit/frontend/history.cljs | 3 ++- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 examples/frontend/src/backend/server.clj diff --git a/examples/frontend/project.clj b/examples/frontend/project.clj index 62d4cfc3..8416bc0a 100644 --- a/examples/frontend/project.clj +++ b/examples/frontend/project.clj @@ -51,4 +51,5 @@ :figwheel {:http-server-root "public" :server-port 3449 - :nrepl-port 7002}) + :nrepl-port 7002 + :ring-handler backend.server/handler}) diff --git a/examples/frontend/resources/public/index.html b/examples/frontend/resources/public/index.html index bbad514c..ce1dd45b 100644 --- a/examples/frontend/resources/public/index.html +++ b/examples/frontend/resources/public/index.html @@ -5,6 +5,6 @@
- + diff --git a/examples/frontend/src/backend/server.clj b/examples/frontend/src/backend/server.clj new file mode 100644 index 00000000..88171cfa --- /dev/null +++ b/examples/frontend/src/backend/server.clj @@ -0,0 +1,11 @@ +(ns backend.server + (:require [clojure.java.io :as io] + [ring.util.response :as resp] + [ring.middleware.content-type :as content-type])) + +(def handler + (-> (fn [request] + (or (resp/resource-response (:uri request) {:root "public"}) + (-> (resp/resource-response "index.html" {:root "public"}) + (resp/content-type "text/html")))) + content-type/wrap-content-type)) diff --git a/modules/reitit-frontend/src/reitit/frontend/history.cljs b/modules/reitit-frontend/src/reitit/frontend/history.cljs index 98d40b0a..96881140 100644 --- a/modules/reitit-frontend/src/reitit/frontend/history.cljs +++ b/modules/reitit-frontend/src/reitit/frontend/history.cljs @@ -96,7 +96,8 @@ (gevents/unlistenByKey listen-key) (gevents/unlistenByKey click-listen-key)) (-get-path [this] - (.. js/window -location -pathname)) + (str (.. js/window -location -pathname) + (.. js/window -location -search))) (-href [this path] path))