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

simple-ui-router

v1.0.4

Published

A simple Javascript UI router.

Downloads

53

Readme

simple-ui-router

A simple javascript UI router

Goals

The aim here is to have a simple pure JS UI router for applications where a full framework and the associated overhead that comes with it is unnecessary.

What it does

  • At a basic level this is just a UI router that can access templates from either elements embedded in the current HTML via a script tag with type "text/html", or from a remote source like a relative URL pointing to an HTML template. The content of the template or html file provided to the route will be injected to the target outlet in the HTML, or the main outlet if the link does not specify a target outlet.

  • In addition to the html content you can also provide a link to one or multiple css or javascript files. These files are treated differently and are injected as link and script tags repectivly, and the script or link tags are only added to the DOM once even if the route is accessed multiple times. Any plumming or scripting that should occur with the route will need to be invoked in the appropriate lifecycle event.

  • Additionally you can provide links to no content (html, css, or js) and use the appropriate callback to handle it however you like. An example of this could be setting up a route for simply performing a put / post to your server and handling the response in the UI that is already displayed.

Lifecycle events in routing process.

All lifecycle events are passed the state object as its parameters.
  • onPostRouteProcessing - Called after the route is processed and any parameters are taken from the URL and added to the state object.
  • onPreFetchContent - Called before the HTML content related to the route is fetched, only if content was fetched related to the route. Specifically only if an ajax call was required to get the HTML content for the route.
  • onPostFetchContent - Called after the HTML content related to the route is fetched, only if content was fetched related to the route. Specifically only if an ajax call was required to get the HTML content for the route.
  • onPreContentLoad - Called before content is loaded related to the route, only if content was loaded related to the route.
  • onPostContentLoad - Called after content is loaded related to the route, only if content was loaded related to the route.
  • handler - Called after all content related to the routing is loaded. This is a good place to set up any code related to the content that was loaded to the page.
  • onPostRoutingHandler - Called at the very end of the routing process. This is after the DOM is scanned for any new links or outlets added via the routed content.
  • onUnloadState - Called before subsequent routing calls on a per outlet basis so long at the route is loads content to the page. If This callback is a good place to do any clean up or plumbing for new content being loaded and the old HTML template being unloaded. Just to note this call is not executed unless the subsequent route loads content to a outlet that currently has content that was placed by routing.

Attributes that signify links and outlets in HTML

  • Links are signified by the attribute route-url where the value of that attribute is url to be used in routing. Links can also specify route-target which tells the router which outlet the link is targeting. If route-target is not specified for a link the it targets the main outlet by default.
  • Outlets are signified by the attribute router-outlet where the value of that attribute is the name of the outlet used for targeting them from links. You can also not provide a name with the attribute and just load a default route to the outlet using the default-route attribute. A few notes on outlets are...
    • There must be an outlet with router-outlet="main" or the router will not start. this is the default outlet.
    • The main outlet is the only outlet that is affected by the default route and any other outlets will not run the default route.
    • You can specify a specific route as a default route for any outlet by giving it a route as the value to the default-route property.

Examples

  • Run ./node_modules/http-server/bin/http-server from the root of the project and navigate to the example folder. ex. 127.0.0.1:8080/example make sure of the correct port by reading the output form http-server.
  • read the code in example/app.js to see how the setup for the router is done, and read example/index.html to see how the attributes are placed to engage the router.

TODO List

  • Add a new attribute for outlets for them to specify a default route for intitial loading.