Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 9, 2018. It is now read-only.

flowmitry/js-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

13 Commits

Repository files navigation

Router

Small and simple JavaScript library for client-side routing.

Requirements

Router works fine in Internet Explorer >=6, Firefox >= 3, Opera, Chrome, Safari. This library is compatible with AMD and CommonJS modules. Also can be exported to global var.

Installing router

# Using jam
jam install router
# Using bower
bower install js-router

Example

// set a prefix if needed
var router = new Router('!');
router
 .when('/', function () {
 // this.request === {}
 })
 .when('/hello/:name', function (name) {
 // for url /hello/john
 // name === 'john'
 // this.request === { 'name': 'john' }
 })
 // we can get request values as arguments
 // or we can use this.request from Route context
 .when('/hello/:name.:surname', function (name, surname) {
 // for url /hello/john.do
 // name === 'john'
 // surname === 'do'
 // this.request === { 'name': 'john', 'surname': 'do' }
 })
 // otherwise function haven't route context, so this.request will be undefined
 .otherwise(function () {
 // this.request === undefined
 })
 .listen();

About

JavaScript library for client-side routing

Resources

License

Stars

Watchers

Forks

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /