All Projects → QubitProducts → Cherrytree

QubitProducts / Cherrytree

Licence: mit
A flexible nested router.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Cherrytree

Routegen
Define your API and SPA routes in one place. Use them anywhere. Only 1.3kb.
Stars: ✭ 86 (-18.1%)
Mutual labels:  router
Fast Path Lede Openwrt
PLEASE GO TO NEW OPENWRT TRUNK BASED SFE FIRMWARE ->
Stars: ✭ 96 (-8.57%)
Mutual labels:  router
Pc Engines Apu Router Guide
Guide to building a Linux or BSD router on the PC Engines APU platform
Stars: ✭ 101 (-3.81%)
Mutual labels:  router
Literoute
LiteRoute is easy transition for your app. Written on Swift 4
Stars: ✭ 90 (-14.29%)
Mutual labels:  router
React Router Scroll Memory
React component to keep the scroll of the page and to restore it if the user clicks on the back button of its browser
Stars: ✭ 95 (-9.52%)
Mutual labels:  router
Twig
Twig - less is more's web server for golang
Stars: ✭ 98 (-6.67%)
Mutual labels:  router
Barba
Create badass, fluid and smooth transition between your website's pages.
Stars: ✭ 9,372 (+8825.71%)
Mutual labels:  router
Router
A simple, compact and fast router package to process HTTP requests
Stars: ✭ 102 (-2.86%)
Mutual labels:  router
Min
A minimalistic web framework with route grouping and middleware chaining
Stars: ✭ 95 (-9.52%)
Mutual labels:  router
Iceworld
tonado的multi-thread 多线程封装
Stars: ✭ 99 (-5.71%)
Mutual labels:  router
Go Tgbot
Golang telegram bot API wrapper, session-based router and middleware
Stars: ✭ 90 (-14.29%)
Mutual labels:  router
Beluganos
The new network OS designed for white-box switches based on open API.
Stars: ✭ 95 (-9.52%)
Mutual labels:  router
Dotweb
Simple and easy go web micro framework
Stars: ✭ 1,354 (+1189.52%)
Mutual labels:  router
Bone
Lightning Fast HTTP Multiplexer
Stars: ✭ 1,270 (+1109.52%)
Mutual labels:  router
Xunleikuainiaoinshell
[ 迅雷快鸟 Shell 版 ] A Shell Implementation of Kuainiao, Xunlei
Stars: ✭ 102 (-2.86%)
Mutual labels:  router
Lit Element Router
A LitElement Router (1278 bytes gzip)
Stars: ✭ 85 (-19.05%)
Mutual labels:  router
Phprouter
PhpRouter is a powerful, minimal, and very fast HTTP URL router for PHP projects
Stars: ✭ 97 (-7.62%)
Mutual labels:  router
Cottage
Simple, fast HTTP router on koa.js.
Stars: ✭ 103 (-1.9%)
Mutual labels:  router
Routes
typed bidirectional routes for OCaml/ReasonML web applications
Stars: ✭ 102 (-2.86%)
Mutual labels:  router
Routersploit
Exploitation Framework for Embedded Devices
Stars: ✭ 9,866 (+9296.19%)
Mutual labels:  router

Cherrytree is a flexible hierarchical router that translates every URL change into a transition descriptor object and calls your middleware functions that put the application into a desired state.

Installation

The size excluding all deps is ~4.83kB gzipped and the standalone build with all deps is ~7.24kB gzipped.

$ npm install --save cherrytree

In a CJS environment

require('cherrytree')

In an AMD environment, require the standalone UMD build - this version has all of the dependencies bundled

require('cherrytree/standalone')

Docs

Demo

See it in action in this demo.

Plugins

To use cherrytree with React, check out cherrytree-for-react.

Usage

var cherrytree = require('cherrytree')

// create the router
var router = cherrytree()
var handlers = require('./handlers')

// provide your route map
router.map(function (route) {
  route('application', {path: '/', abstract: true}, function () {
    route('feed', {path: ''})
    route('messages')
    route('status', {path: ':user/status/:id'})
    route('profile', {path: ':user'}, function () {
      route('profile.lists')
      route('profile.edit')
    })
  })
})

router.use(function render (transition) {
  transition.routes.forEach(function (route, i) {
    route.view = handlers[route.name]({
      params: transition.params,
      query: transition.query
    })
    var parent = transition.routes[i-1]
    var containerEl = parent ? parent.view.el.querySelector('.outlet') : document.body
    containerEl.appendChild(view.render().el)
  })
})

router.use(function errorHandler (transition) {
  transition.catch(function (err) {
    if (err.type !== 'TransitionCancelled' && err.type !== 'TransitionRedirected') {
      console.error(err.stack)
    }
  })
})

// start listening to URL changes
router.listen()

Examples

You can clone this repo if you want to run the examples locally:

A more complex example in it's own repo:

Features

  • can be used with any view and data framework
  • nested routes are great for nested UIs
  • generate links in a systematic way, e.g. router.generate('commit', {sha: '1e2760'})
  • use pushState with automatic hashchange fallback
  • all urls are generated with or without # as appropriate
  • link clicks on the page are intercepted automatically when using pushState
  • dynamically load parts of your app during transitions
  • dynamic segments, optional params and query params
  • support for custom query string parser
  • transition is a first class citizen - abort, pause, resume, retry. E.g. pause the transition to display "There are unsaved changes" message if the user clicked some link on the page or used browser's back/forward buttons
  • navigate around the app programatically, e.g. router.transitionTo('commits')
  • easily rename URL segments in a single place (e.g. /account -> /profile)

How does it compare to other routers?

  • Backbone router is nice and simple and can often be enough. In fact cherrytree uses some bits from Backbone router under the hood. Cherrytree adds nested routing, support for asynchronous transitions, more flexible dynamic params, url generation, automatic click handling for pushState.
  • Ember router / router.js is the inspiration for cherrytree. It's where cherrytree inherits the idea of declaring hierarchical nested route maps. The scope of cherrytree is slightly different than that of router.js, for example cherrytree doesn't have the concept of handler objects or model hooks. On the other hand, unlike router.js - cherrytree handles browser url changes and intercepts link clicks with pushState out of the box. The handler concept and model hooks can be implemented based on the specific application needs using the middleware mechanism. Overall, cherrytree is less prescriptive, more flexible and easier to use out of the box.
  • react-router is also inspired by router.js. React-router is trying to solve a lot of routing related aspects out of the box in the most React idiomatic way whereas with cherrytree you'll have to write the glue code for integrating into React yourself (see cherrytree-for-react plugin). However, what you get instead is a smaller, simpler and hopefully more flexible library which should be more adaptable to your specific needs. This also means that you can use a react-router like approach with other React inspired libraries such as mercury, riot, om, cycle, deku and so on.

CI

Build Status build status

Browser Support

Sauce Test Status

Cherrytree works in all modern browsers. It requires es5 environment and es6 promises. Use polyfills for those if you have to support older browsers, e.g.:

Acknowledgement

Thanks to Marko Stupić for giving Cherrytree a logo from his http://icon-a-day.com/ project!

FAQ

  • Why is cherrytree written as one word? You got me, I'd say that represents the wabisabi nature of the library.

Want to work on this for your day job?

This project was created by the Engineering team at Qubit. As we use open source libraries, we make our projects public where possible.

We’re currently looking to grow our team, so if you’re a JavaScript engineer and keen on ES2016 React+Redux applications and Node micro services, why not get in touch? Work with like minded engineers in an environment that has fantastic perks, including an annual ski trip, yoga, a competitive foosball league, and copious amounts of yogurt.

Find more details on our Engineering site. Don’t have an up to date CV? Just link us your Github profile! Better yet, send us a pull request that improves this project.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].