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

simple-githubpages-spa-router

v1.0.1

Published

Simple web router for SPA hosted in Github Pages

Downloads

2

Readme

simple-githubpages-spa-router

Simple web router for SPA hosted with Github Pages

Disclaimer

Im not by any means an experienced web developer. This repository started as a side project while developing my personal Devlog web page with Github Pages.

I'm using this side project for personal studying purposes only.

Topics I'm studying with this project:

  • Typescript (the basics)
  • Library development with typescript
  • Manipulation of the Window Location and History properties with Javascript
  • The basics of how SPA's could work under the hood
  • Client side rendering ideas

Any comments are completely welcome. I am passionate about always learning new things.

About

This is a simple web router written in Typescript that can help you if you are trying to build a simple SPA using Github Pages as your hosting service.

Requirements

  • Rollup or any other bundler or library that lets you resolve Node module imports on the client side when building your project

Usage

Installation

You can install the library as a npm package with the next command:

$ npm install simple-githubpages-spa-router

createRouter()

Parameters:

routes

Array of the routes defined for the project.

For more information on creating routes please use this example.

repoName

Name of the page repository, this parameter is optional and you can define it only if your github page does not count with a custom domain and it is using the defatult one, example: github.io/repoName/

customListener

An optional custom method, that will be attached to the listener for the event "popstate" from the window element. If not defined, the router will use the default listener method.

Creating routes

A route is represented as an object with the following structure:

// Render method example
function renderAbout() {
    body = document.getElementById("body");
   
    body!.innterHTML = `<h1> About </h1>`;
}

var route = { "/about", renderAbout }

Basic implementation

Import the module into your main javascript file and use the method createRouter() to initialize a new gpSpaRouter instance to use in your project.

// index.js
import renderMethod1 from "./first_module";
import renderMethod2 from "./second_module";

import { createRouter } from "simple-githubpages-spa-router";

let router = createRouter([
    {path: "/first_path", pageRenderer: renderMethod1},
    {path: "/second_path", pageRenderer: renderMethod2},
]);

Creating anchor <a> tags for navigation

You can tell your web page when to render the content attached to a path by using the <a> tag and writing the path as a reference with the hash format:

<a href="#/myPage"> Render my content </>

You can still use normal hash paths to anchor segments in your page, just remember to remove the / from the path.

| Normal hash path | Router hash path | |-|-| | #about | #/about |

Redirecting to the main page

By default, the hashed path #/ is reserved for reloading the index.html in case you want to use it to take you to the main page.

Handling page reload

By default, github pages will redirect you to a 404 error page when trying to load a path that does not exist. The custom 404.html page created in your repository would prevent this by parsing the custom path in the URL as a query parameter and redirecting you to the main HTML document. By doing this, the router can catch the requested path and render out the content.

To do list:

  • [ ] Handling of nested paths
  • [ ] Support for a custom 404 error page renderer method