Code Monkey home page Code Monkey logo

avenue's Introduction

avenue

Clojars Project

A super simple routing library, written in ClojureScript.

Overview

This comes later.

Usage

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)

Caveats / Gotchas

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)

Emojis in commits?

๐ŸŒฑ โ†’ new feature

๐Ÿ‚ โ†’ cleanup of some sort

๐Ÿ โ†’ fixed a bug or error

License

Copyright ยฉ 2014 Chris Etheridge

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.