A simple client-side Javascript/jQuery router.
I created this project because I needed a navigation that maintains some parts of the page running when the user navigate through the website. The idea here is to use js/jquery to load the pages via ajax.
It was created without any planning, the features were emerging according to the needs of each project, so the code is not finished yet.
- Maintains parts of the page running during navigation (music players, timesheets).
- Separating mobile and desktop pages dynamic, running under the same domain. For example: at the address http://domain.com/products we can load on desktop the page /views/desktop/products.php and on mobile /views/mobile/products.php.
- Create different types of navigations and a better experience on different devices. For example: on mobile we can navigate like apps, using tabs and maintaining the content loaded, but normal on desktop, loading the full page.
var router = new Routeur(allLinks = true, mobilePages = true, rootFolder = 'views');
mobilePages set true is to create different pages for desktop and mobile. rootFolder is where the pages are located.
router.add({ url:'product/{id}/{tab}', phpFile: 'product-tab.php'});
router.add({ url:'product/{id}', phpFile: 'product.php'});
router.add({ url:'categories', phpFile: 'categories.php'});
router.add({ url:'list', phpFile: 'list.php'});
router.add({ url:'/', phpFile: 'index.php'});
router.add({ url:'*', phpFile: 'profile.php'});
The last item, * uses id as parameter. The page used in the example, profile.php, will be loading like profile.php?id={url_typed}
router.run();
Remember to point all pages to index.php or to the default page you use.
- jQuery
- History.js