Ported from Respo/respo-router.
Demo http://repo.respo-mvc.org/respo-router.calcit .
respo-router.listener :refer $ listen!
respo-router.parser :refer $ parse-address
respo-router.format :refer $ strip-sharp
respo-router.core :refer $ render-url!
; router rules
def dict $ []
:: :room $ [] "|room-id"
:: :team $ [] "|team-id"
:: :search $ []
; :hash | :history
def mode :history
; listen to router and dispatch actions
listen! dict dispatch! mode
; /a/b?c=d
parse-address path dict
; render url
add-watch *store :changes $ fn ()
render-url! (:router @*store) dict mode
Based on a dict:
def dict $ []
:: :team $ [] |team-id
:: :room $ [] |room-id
:: :search $ []
Router data structure for:
/team/t12345/room/r1234?a=1&b=2
looks like:
{}
:path $ []
:: :team "|t12345"
:: :room "|r1234"
:query $ {}
"|a" 1
"|b" 2
Some special routes:
[]
represents/
404
is generated when no route is matched
https://github.com/calcit-lang/respo-calcit-workflow
MIT