shadowvzs / js-router

Router for (vanilla) JS for SPA (apache2 with .htccess)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

js-router

Router for (vanilla) JS and apache https://github.com/shadowvzs/js-router/tree/master/project/js/base

Note:

  • this is usefull for Single Page Apps :)
  • you can see alot files but the router itself mostly only:
    • Router.js (or Router class)
    • Routes.js (or routes object)
    • Validator.js (regex validator object)

Features

  • Lightweight client side page router
  • Catch both regular pieces ("/"), query strings ("?/&"), hash ("#")
  • Work well with any url rewrite services (example: apache2 with .htaccess)
  • Routes declareable separate in routes object
  • Parameters in like ex. :slug and validation (Validator.js) for it
  • Parameters can be optional if you use "." (dot) at end of parameter
  • You can assign name which will handle the route: ex TestPage object (Routers.js:133)
  • If you use link which start with "/" then it will be internal link, router handle that

Example

const routes = [
    ['/atm/dadam/:slug.', null, ['SLUG'], "TestPage" ],
    ['/home', null, false, "HomePage" ],
    ['/error/:id', null, ['NUMBER'], "ErrorPage" ],
];

How it's work - Video

Test


About

Router for (vanilla) JS for SPA (apache2 with .htccess)


Languages

Language:JavaScript 95.8%Language:HTML 2.6%Language:Shell 1.6%