Skip to content

Latest commit

 

History

History
41 lines (35 loc) · 1.06 KB

README.md

File metadata and controls

41 lines (35 loc) · 1.06 KB

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.