🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

quilk-frontend-router

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quilk-frontend-router

A lightweight router for es6. No dependencies. Works perfectly with jQuery and Vanilla JS

Source
npmnpm
Version
1.0.5
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

quilk-frontend-router

A simple router for your custom js apps. A simple, small and fast router with a tiny production weight of 1.3kb, also with zero dependencies.

How to use it

This is your front door in... include the routing module and pass in your routes.

import $ from 'jquery';
import QuilkFrontendRouter from 'quilk-frontend-router';
import routes from './routes';
$(document).ready( () => { new QuilkFrontendRouter( routes ) } );

In this example the routes could look like:

// Import your controllers:
import indexController from './controllers/indexController';
import contactUsController from './controllers/contactUsController';
import sliderController from './controllers/sliderController';
import blogController from './controllers/blogController';

/**
 * Example straight key:
 * '/this-route-only/'
 * 
 * The above will only match if the pathname is the same as the key, ie:
 * '/this-route-only'
 * '/this-route-only/'
 *
 *
 * Example key with params:
 * '/some-route/(controller-a|controller-b|controller-b/param_a)'
 *
 * The above will call the array of controller classes provided if the incoming url pathname is any of the following list, but nothing more:
 * '/some-route/'
 * '/some-route/controller-a'
 * '/some-route/controller-b'
 * '/some-route/controller-b/param_a'
 *
 * Exmaple wildcard key:
 * '/somepath/*'
 *
 * The above will call the array of controller classes provided if the incoming url pathname is any of the following list, but nothing more:
 * '/some-route/'
 * '/some-route/*' basically it matches everything after the key '/somepath'
 * 
 */
 
export default {
    '/':   [ indexController ],
    '/contactUsController/(thanks)':  [ contactUsController ],
    '/blog-posts/*':  [ blogController, sliderController ]
};

The controllers just require a construct and you're good to go. Here is what the indexController could look like. This would console log 'This is the index controller' when the url pathname was '/':

export default class indexController {

    constructor () {
        this.logIt();
    }
    
    logIt () {
        console.log( `This is the index controller` );
    }
}

Keywords

router

FAQs

Package last updated on 07 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts