Merge pull request #125 from metosin/frontend-fragment

Frontend fixes
This commit is contained in:
Juho Teperi 2018-08-23 10:12:46 +03:00 committed by GitHub
commit 2900e96337
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 9 deletions

View file

@ -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})

View file

@ -5,6 +5,6 @@
</head>
<body>
<div id="app"></div>
<script src="js/app.js"></script>
<script src="/js/app.js"></script>
</body>
</html>

View file

@ -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))

View file

@ -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})

View file

@ -5,6 +5,6 @@
</head>
<body>
<div id="app"></div>
<script src="js/app.js"></script>
<script src="/js/app.js"></script>
</body>
</html>

View file

@ -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))

View file

@ -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)))))

View file

@ -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))

View file

@ -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}}})