diff --git a/examples/frontend-controllers/project.clj b/examples/frontend-controllers/project.clj index feab3f83..e758882b 100644 --- a/examples/frontend-controllers/project.clj +++ b/examples/frontend-controllers/project.clj @@ -49,4 +49,6 @@ :figwheel {:http-server-root "public" :server-port 3449 - :nrepl-port 7002}) + :nrepl-port 7002 + ;; Server index.html for all routes for HTML5 routing + :ring-handler backend.server/handler}) diff --git a/examples/frontend-controllers/resources/public/index.html b/examples/frontend-controllers/resources/public/index.html index bbad514c..ce1dd45b 100644 --- a/examples/frontend-controllers/resources/public/index.html +++ b/examples/frontend-controllers/resources/public/index.html @@ -5,6 +5,6 @@
- + diff --git a/examples/frontend-controllers/src/backend/server.clj b/examples/frontend-controllers/src/backend/server.clj new file mode 100644 index 00000000..88171cfa --- /dev/null +++ b/examples/frontend-controllers/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/examples/frontend/project.clj b/examples/frontend/project.clj index 62d4cfc3..4f651748 100644 --- a/examples/frontend/project.clj +++ b/examples/frontend/project.clj @@ -51,4 +51,6 @@ :figwheel {:http-server-root "public" :server-port 3449 - :nrepl-port 7002}) + :nrepl-port 7002 + ;; Server index.html for all routes for HTML5 routing + :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.cljs b/modules/reitit-frontend/src/reitit/frontend.cljs index 83dd3d01..692143b6 100644 --- a/modules/reitit-frontend/src/reitit/frontend.cljs +++ b/modules/reitit-frontend/src/reitit/frontend.cljs @@ -22,9 +22,10 @@ (let [uri (.parse Uri path)] (if-let [match (r/match-by-path router (.getPath uri))] (let [q (query-params uri) + match (assoc match :query-params q) ;; Return uncoerced values if coercion is not enabled - so ;; that tha parameters are always accessible from same property. - parameters (or (coercion/coerce! (assoc match :query-params q)) + parameters (or (coercion/coerce! match) {:path (:path-params match) :query q})] (assoc match :parameters parameters))))) diff --git a/modules/reitit-frontend/src/reitit/frontend/history.cljs b/modules/reitit-frontend/src/reitit/frontend/history.cljs index 98d40b0a..9b59fe0e 100644 --- a/modules/reitit-frontend/src/reitit/frontend/history.cljs +++ b/modules/reitit-frontend/src/reitit/frontend/history.cljs @@ -1,7 +1,6 @@ (ns reitit.frontend.history "" (:require [reitit.core :as reitit] - [goog.events :as e] [reitit.core :as r] [reitit.frontend :as rf] [reitit.impl :as impl] @@ -89,14 +88,15 @@ (-on-navigate this (-get-path this)) (assoc this :listen-key (gevents/listen js/window goog.events.EventType.POPSTATE handler false) - :click-listen-key (e/listen js/document e/EventType.CLICK ignore-anchor-click)))) + :click-listen-key (gevents/listen js/document goog.events.EventType.CLICK ignore-anchor-click)))) (-on-navigate [this path] (on-navigate (rf/match-by-path router path) this)) (-stop [this] (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)) diff --git a/test/cljs/reitit/frontend/core_test.cljs b/test/cljs/reitit/frontend/core_test.cljs index 03586309..20009088 100644 --- a/test/cljs/reitit/frontend/core_test.cljs +++ b/test/cljs/reitit/frontend/core_test.cljs @@ -20,6 +20,7 @@ {:template "/" :data {:name ::frontpage} :path-params {} + :query-params {} :path "/" :parameters {:query {} :path {}}}) @@ -32,6 +33,7 @@ {:template "/foo" :data {:name ::foo} :path-params {} + :query-params {} :path "/foo" :parameters {:query {} :path {}}}) @@ -59,6 +61,7 @@ (is (= (r/map->Match {:template "/:id" :path-params {:id "5"} + :query-params {} :path "/5" :parameters {:query {} :path {:id 5}}}) @@ -71,7 +74,7 @@ (is (= (r/map->Match {:template "/:id" :path-params {:id "5"} - ;; Note: query not included in path + :query-params {:mode "foo"} :path "/5" :parameters {:path {:id 5} :query {:mode :foo}}}) @@ -84,6 +87,7 @@ (is (= (r/map->Match {:template "/:id" :path-params {:id "5"} + :query-params {:mode "foo"} :path "/5" :parameters {:path {:id 5} :query {:mode :foo}}})