Simple nested router component for Respo
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
assets
src/respo_router
.gitattributes
.gitignore
README.md
calcit.edn
meyvn.edn
package.json
shadow-cljs.edn
yarn.lock

README.md

Respo Router

This project is in early stage...

Demo http://router.respo-mvc.org/

Usage

Clojars Project

[respo/router "0.4.0"]
[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)))

Router IR

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 [{:name "team", :data {"team-id" "t12345"}}
        {:name "room", :data {"room-id" "r1234"}}],
 :query {"a" 1, "b" 2}}

Some special routes:

  • [] represents /
  • 404 is generated when no route is matched

Develop

yarn watch
# another terminal
yarn dev
# open http://localhost:8080

https://github.com/mvc-works/coworkflow

Test

yarn compile-test
node target/test.js

License

MIT