Coder Social home page Coder Social logo

router's Introduction

router

Simple client-side router.

Installation

$ component install component/router

Examples

Example with only setup callbacks:

var Router = require('router');

var router = new Router;

router.get('/user/:id', function(id){
  console.log('show %s', id);
});

router.dispatch('/user/2');

Setup and teardown callbacks for unbinding events etc:

var Router = require('router');

var router = new Router;

router.get('/user/:id', function(id){
  console.log('show %s', id);
}, function(id){
  console.log('hide %s', id);
});

router.dispatch('/user/2');
router.dispatch('/user/5');
router.dispatch('/user/10');

Fluent api equivalent of above:

var Router = require('router');

var router = new Router;

router.get('/user/:id')
.before(function(id){
  console.log('show %s', id);
})
.after(function(id){
  console.log('hide %s', id);
});

router.dispatch('/user/2');
router.dispatch('/user/5');
router.dispatch('/user/10');

License

MIT

router's People

Contributors

tj avatar forbeslindesay avatar

Stargazers

Russell Chapman avatar Lesley avatar Andrew Shapiro avatar Uri Acuesta avatar zcoding avatar Tolia avatar zekai avatar Joseph Werle avatar Nikos M. avatar Paul Cookie avatar Aleksey Kulikov avatar Mohammad Sadegh Khoeini avatar Behrang Norouzinia avatar Dmitry Chestnykh avatar Cristian Douce avatar Neil Jagdish Patel avatar Daniel Fagnan avatar Fabian Eichenberger avatar Shimaguchi Tomoya avatar Eivind Fjeldstad avatar Bent Cardan avatar Flávio Juvenal avatar 迁移到 leogiese avatar Shawn Jonnet avatar Christian Sullivan avatar Nicola avatar Julian Gruber avatar 刘巍峰 avatar Simon Kusterer avatar Chen Yangjian avatar Ben Evans avatar

Watchers

Guillermo Rauch avatar  avatar Nathan Rajlich avatar Damián Suárez avatar James Cloos avatar Shimaguchi Tomoya avatar Carly Stambaugh avatar  avatar

router's Issues

future of this component?

hey tj, i remember seeing you mention in page.js that you weren't really happy with its api, and were instead going for one more similar to this one (i think i remember that).

curious to know what kinds of things you are expecting to do here, i assume this is the aggregate component like dom that will be pretty fully functional on its own.

i'm happy to help build some of them. a couple of things i'm thinking of:

  • router.start() method - so that we dont have to dispatch with the path, query, hash every time to kick things off.
  • hash support - speaking of it.
  • pushstate - i'd like to be able to send the router to different places and update the url at the same time. i imagined it would be called router.go(path).
  • optional pieces - it would be nice not to have to define multiple routes when there are optional arguments

idea: Router#listen

basically i want an easy way to turn on link-delegateing. i was thinking listen would handle that automatically for me, so just:

router.listen();

would start listening for links that should get routed. but then the real bonus is that i can listen to just certain subsets of paths, since i might have my app at https://segment.io/ianstormtaylor/project and only everything after /project is routable in this "app", everything else requires a pageload. right now link-delegate isnt setup nicely to do that. but with listen it's just:

router.listen('/path');

i'm working this idea into my edits on my segmentio/router fork. let me know if you see any problems/changes you think should be made

maybe the path subsetting should be in link-delegate?

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.