npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vanilla-router

v1.2.8

Published

JS vanilla Router

Downloads

580

Readme

vanilla-router

NPM

NPM

Description

Simplest One Page Application Router for those who want to use it on Vanilla JS

Note: If you want to use the IE compatible version use v1.1.5

Installation

NPM

npm install vanilla-router --save

Bower

bower install vanilla-router --save

Usage

var router = new Router({
    mode: 'history',
    page404: function (path) {
        console.log('"/' + path + '" Page not found');
    }
});

router.add('', function () {
    console.log('Home page');
});

router.add('hello/(:any)', function (name) {
    console.log('Hello, ' + name);
});

router.add('about', function () {
    console.log('About Page');
});

router.addUriListener();

router.navigateTo('hello/World');

Options

mode string

Default: "history" .

  • hash - is for hashbang routes based on window.location.hash
  • history - is for clean url routes based on HTML5 functionality. It is also provide back-compatibility for old browser.

root string

Default: "/" .

Root represents the relative path for the project root.

page404 function

Default: function that log an error in console.

Callback function for 404 page

routes Array

Default: [ ]

Warning! Use it only if you have all stack with RegExp routes.

Methods

Every public methods of Router return the instance of Router, so they can be chained.

add(path, handler, options)

Add a route and handler for this route

Parameters
  • path - string | RegExp
  • handler - callback if the URL will match the path
  • options - object, you can specify before unload callback

string path can contain:

  • parenthesis (( )) - value between them is sent to callback function
  • wildcards (:any, :num, :word) it doesn't pass the value to callback function
  • named placeholder ({variableName}) it pass the value to the callback function
router.add('hello/world', function(){ });
router.add('hello/:word', function(){ });
router.add('hello/(:word)', function(name){ });
router.add('hello/{name}', function(name){ });
router.add(/^hello\/(\w+)/i, function(name){ });

remove(path)

Remove the route from current list of routes by path

navigateTo(path[, state[, silent]])

Navigate to the specific URI with optional additional state of page silent is a flag, set as true, to skip check for new URL

check()

Check the current URL for a change

back()

Simulate the browser "Back" button

forward()

Simulate the browser "Forward" button

go(step)

Go to a specific step in history

refresh()

Recall current route handler with same arguments

addUriListener()

Add the event listener for URL change

removeUriListener()

Remove the event listener for URL change

reset()

Reset all setting and state of Router

Licence

Released under the MIT license

Copyright (c) 2016 Grigore Odajiu