Skip to content

beogip/route.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Route.js

Route.js allows executing JavaScript code in the browser under a specific url

Setup

Include the Route.js script in your HTML markup:

<script src="js/route.min.js"></script>

Usage

In your application code, use the route() function like this:

//if the browser url is /some/url
route("/some/url", function(data)
{
  //this code will run
});

You can get the url parameters

//if the browser url is /some/foo
route("/some/:id", function(data)
{
  //this code will run and data.id is equal to 'foo'
});

You can use a wildcard to run the code in all the urls

route("*", function(data)
{
  //this code will run in any url
});

API

The route() function accepts a string as first argument. The second argument must be a callback function, which is called if the first argument matchs with the browser url. The callback function receives only one argument, wich is an object with the url params.

License

Copyright 2015 Juan Ignacio Gipponi. Licensed under the MIT License. See the LICENSE file for more information.

About

Route.js allows executing JavaScript code in the browser under a specific url

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published