Skip to content

alejandrolechuga/HashRouter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 

Repository files navigation

HashRouter.js

Simple hash routing library, doesn't require any dependency. It routes strings after the symbol "#".

Routing

url : http://localhost/index.html#home ```javascript hrouter("home", function () { $('#text').html("Home ! "); }); ```

Parameters

url : http://localhost/index.html#home/1 ```javascript hrouter("home/:page", function (page) { $('#text').html("Home page #" + page); }); ```

Fragments

url : http://localhost/index.html#greetings/page1 ```javascript hrouter("greetings/page:number", function(number) { $('#text').html("Home page # " + number); }); ```

Multiple Parameters

url : http://localhost/index.html#greetings/page1/contact ```javascript hrouter("greetings/page:number/:section", function(number, section) { $('#text').html("Home page # " + number + " section " + section); }); ```

Wildcard

url : http://localhost/index.html#search/zombies-without-eyes ```javascript hrouter("search/*",function (search) { $('#text').html(" Find this text *" + search + "*"); });
<h3>Optional</h3>
<strong>url</strong> : http://localhost/index.html#user
<strong>url</strong> : http://localhost/index.html#user/12
```javascript
hrouter("user/:id?", function (id) {
  if (id) {
    $('#text').html("Alejandro's id is" + id);
  } else {
    $('#text').html("User not found");
  } 
}, function (id) {
  if (id) {
    document.title = "Alejandro's Profile";
  } else {
    document.title = "Unknown Profile";
  }
});

Dispatch current hash

```javascript hrouter(); ```

Dispatch

```javascript hrouter("user/1"); ```

Break next matches

```javascript hrouter("home/:page", function (page) { $('#text').html("Home page #" + page); return false; }); hrouter("home/:page", function (page) { $('#text').html("Home page = " + page); }); ```

About

Simple hash routing library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published