A super simple routing library, written in ClojureScript.
This comes later.
Using avenue
is pretty simple.
Add the following to your project.clj
[avenue "X.X.X"]
where X.X.X
is the current version.
Then, require it in a namespace:
(ns my-ns.core
(:require [avenue.core :as avenue]))
Now you need to set up avenue
. First, let's add some routes and set our config:
(ns ui.routes
(:require [avenue.core :as avenue]))
;; set where we want to mount our pages
(avenue/set-mount-point! "my_mount_point_id")
(avenue/add-route :kitty
:match #"/"
:ctor kitty/index-ctor)
(avenue/add-route :doggy
:match #"/woof"
:ctor doggy/index-ctor)
Note: If you do not set-mount-point!
, then react_mount
will be used as a fallback.
Now, we can call / render our routes!
;; go to a route via a URL
(avenue/go! "mygreatapp.com/woof")
;; reload at a URL
(avenue/reload! "mygreatapp.com")
;; check if a URL matches a current route
(avenue/matches-current-route? "mygreatapp.com/dog/stuff")
;; get the current route (this returns a route map)
(avenue/current-route)
Reload your routes when your app starts or when Figwheel reloads. This can cause components to not update when their code has changed.
(defn ^:export reload! []
(avenue/refresh!)
(my-routes/refresh!))
;; wehre my-routes is:
(ns my-routes
(:require [avenue.core :as avenue]))
(avenue/add-route :kitty
:match #"/"
:ctor kitty/index-ctor)
(avenue/add-route :doggy
:match #"/woof"
:ctor doggy/index-ctor)
🌱 → new feature
🍂 → cleanup of some sort
🍁 → fixed a bug or error
Copyright © 2014 Chris Etheridge
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close