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 🙏

© 2025 – Pkg Stats / Ryan Hefner

js-spa-router

v0.0.5

Published

Simple JS Routing Framework for SPA

Downloads

15

Readme

js-spa-router

Simple JS Routing Framework for SPA. Doesn't use external libraries. The underlying state management system is also built natively. This is WIP but still you can try and give your feedback.

API

Lifecycle Hooks

In SPA Router every route has a list of state or otherwise called as route hooks which enables the developer to configure appropriate callback actions.

Hooks

  • mountRoute Mounts the current route and setup the foundation. You can initialize the route context here.
  • loadData Load the data for the current route. Any call to server can be configured here.
  • render Render the UI for the current route. Initialize all components and perform other page specific activities.
  • unloadData Remove unwanted data from the current route context. Unloads all data that are not needed in the future.
  • unmountRoute Remove / Clears the current route context.
  • destroy Destructor for the current route.

Transition

Transition logically notifies the state change. It happens in three phases as given below:

Syntax

JSSPARouter.transitions() Returns all possible transitions

Example

  • transition.before called before the transition starts
  • transition.start called during the transition
  • transition.after called after the transition completes

State

Every state get executed in a sequence of five phases. This will be super useful when you logically want to split your action.

Syntax

JSSPARouter.states() Returns all possible states

Example

  • state.leave Before the current state leaves
  • state.left After the current state left
  • state.enter When the current state enter
  • state.reached When the current state reach
  • state.entered After the current state entered

Usage

	// Sample JS SPA Router

  /*
   * @method callback
   * @description Hook to handle route state change and route transitions
   * @param {string} type Describes The Transition Type
   * @param {object} transition The real transition object
   * @param {object} currentRoute The current route object
   */
  let callback = function(type, transition, currentRoute) {
  };

  // Sample JS SPA Router Config Payload
  let jssparouter = JSSPARouter.map({
    "/": {
      id: 'root',
      path: '/',
      callback: callback,
      index: '/',
      child: {
        "categories": {
          id: 'categories',
          path: 'categories',
          callback: callback,
          child: {
            "mobile": {
              id: 'mobile',
              path: 'mobile',
              callback: callback
            },
            "desktop": {
              id: 'desktop',
              path: 'desktop',
              callback: callback
            },
            "laptop": {
              id: 'laptop',
              path: 'laptop',
              callback: callback
            }
          }
        },
        "support": {
          id: 'support',
          path: 'support',
          callback: callback,
          child: {
            "email": {
              id: 'email',
              path: 'email',
              callback: callback
            },
            "phone": {
              id: 'phone',
              path: 'phone',
              callback: callback
            }
          }
        }
      }
    }
  });
  <button type="button" onclick="JSSPARouter.gotoPath('/categories')">Categories</button>
  <button type="button" onclick="JSSPARouter.gotoPath('/categories/mobile')">Mobile</button>
  <button type="button" onclick="JSSPARouter.gotoPath('/categories/laptop')">Laptop</button>
  <button type="button" onclick="JSSPARouter.gotoPath('/categories/desktop')">Desktop</button>
  <button type="button" onclick="JSSPARouter.gotoPath('/support')">Support</button>
  <button type="button" onclick="JSSPARouter.gotoPath('/support/email')">Email</button>
  <button type="button" onclick="JSSPARouter.gotoPath('/support/phone')">Phone</button>

Installation

  • yarn add js-spa-router