我已经使用 clojure 的 noir 框架创建了一个 Web 项目,并想尝试使用 pre-route 宏。
这是我的 test.clj
(ns website.views.test
(:require [website.views.common :as common] [noir.content.getting-started])
(:use [noir.core :only [defpage]])
(:use [hiccup.core :only [html]])
(:require noir.core))
(defn is-admin? [] false)
(pre-route '/admin/*' (when-not (is-admin?) (redirect '/login')))
(defpage "/login" [] (common/layout [:p "login to website"]))
(defpage "/admin" [] (common/layout [:p "Welcome to admin page"]))
(defpage "/admin/test1" [] (common/layout [:p "Welcome to admin test1 page"]))
(defpage "/admin/test2" [] (common/layout [:p "Welcome to admin test2"]))
当我执行“lein run”时,我得到以下堆栈跟踪
Caused by: java.lang.RuntimeException: Invalid token: /admin/*'
at clojure.lang.Util.runtimeException(Util.java:170)
at clojure.lang.LispReader.interpretToken(LispReader.java:321)
at clojure.lang.LispReader.read(LispReader.java:206)
at clojure.lang.LispReader$WrappingReader.invoke(LispReader.java:537)
at clojure.lang.LispReader.readDelimitedList(LispReader.java:1126)
at clojure.lang.LispReader$ListReader.invoke(LispReader.java:962)
at clojure.lang.LispReader.read(LispReader.java:180)
at clojure.lang.Compiler.load(Compiler.java:6949)
... 51 more
知道什么可能是导致此异常的原因(当我注释掉预路由宏时不会发生)?