我像在cljs应用程序中一样在bidi中定义了路由:
(def routes
["" {
"/foo" :bar
["/items" :id] :item-do}]
)
(defn- parse-url [url] (bidi/match-route routes url))
(defn- dispatch-route [matched-route]
(let [panel-name (keyword (name (:handler matched-route)))]
(dispatch [:active-panel panel-name])))
(def history (pushy/pushy dispatch-route parse-url))
[当我转到路线“ / foo”时,显示的面板与:bar
关联,但是当我转到路线项目/某个随机字符串时,我希望看到与:item-do
关联的面板,但看到的却是空白页,并在控制台中显示:
Uncaught SyntaxError: Unexpected token '<' myapp.js 1
Reference Error: myapp is not defined. somerandomstring:14
我在做什么错,我该如何解决?我如何正确匹配比迪里uri中的任意字符串?
您的语法有点错误:
(ns tst.demo.core
(:use tupelo.core tupelo.test)
(:require
[bidi.bidi :as bidi] ))
(dotest
(let [routes ["" {"/foo" :bar
"/items/" {[:id] :item-do}}]]
(spyx (bidi/match-route routes "/foo" :request-method :get))
(spyx (bidi/match-route routes "/items/abc" :request-method :get))) )
产生所需的输出:
(bidi/match-route routes "/foo" :request-method :get)
=> {:handler :bar,
:request-method :get}
(bidi/match-route routes "/items/abc" :request-method :get)
=> {:route-params {:id "abc"},
:handler :item-do,
:request-method :get}