clojure - In ClojureScript, why can't I navigate to a URL entered by hand, but if I click a link it works? -
(note, i'm using reagent, secretary, , compojure (among others))
i want create route /sectest/:id, , if point browser route, following error:
resource interpreted stylesheet transferred mime type text/html: "http://localhost:3449/sectest/css/site.css". asdf:1 refused execute script 'http://localhost:3449/sectest/js/app.js' because mime type ('text/html') not executable, , strict mime type checking enabled.
but if click on link in browser navigates route, works fine...
here's pertinent code:
client side:
(secretary/defroute "/sectest/:id" [id] (do (js/console.log (str "hi " id)) (session/put! :current-page #'my-page))) server side:
(defroutes routes (get "*" [] loading-page) ;this anticipates client-side routing (get "/cards" [] cards-page) (resources "/") (not-found "not found")) (def app (wrap-middleware #'routes)) so following link takes me my-page, , console prints "hi asdf" fine:
[:div [:a {:href "/sectest/asdf"} "sectest"]] but if type in http://localhost:3449/sectest/asdf, error, , can't seem trace it. suspect might have code trying find resources located @ /sectest, (which shouldn't), can't confirm or figure out how work it... am new clojure, forgive if i'm massively ignorant on point, thoughts?
take @ server side routing, have 1 route:
(get "*" [] loading-page) as handles following routes never trigger. order matters:
(defroutes routes (get "/cards" [] cards-page) (resources "/") (get "*" [] loading-page) ;this anticipates client-side routing ) the above should trick, removed 404 route, should handled frontend routing.
the reason works when clicking on page link in spa handled secretary. if enter url manually doing page reload , request handled compojure initially.
edit:
after taking closer look, relative links css/js files in html template culprit here:
/sectest/js/app.js the compojure resources route won't match , default catch route loading-page served css/js file browser. hence error.
for dev env had correct :asset-path of boot cljs task source mapping files suffered problem. should similiar lein-figwheel.
Comments
Post a Comment