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

@jamilservices/sb-module-router

v1.0.4

Published

Simply Builder Module - Create, Manage, and Destroy Routes

Downloads

93

Readme

@jamilservices/sb-module-router

The @jamilservices/sb-module-router is designed to provide a robust and flexible routing system for web applications built with SimplyBuilder. It integrates seamlessly with the SimplyBuilder environment, allowing developers to manage route changes, state transitions, and navigation events efficiently.

SimplyBuilder SimplyBuilder SimplyBuilder - sb-module-router GitHub License

Features

  • Dynamic Routing: Easily manage your app's routes with support for sound path matching.
  • State Management: Easily obtain the status of your routes and navigations.
  • Event Notifications: Receive route change events during navigation activities.
  • Simplified API: Offers a simple API for subscribing to events, registering routes, cleaning listeners, and navigating between registered routes with minimal code.
  • Module Integrity: The API is frozen to prevent runtime modifications, ensuring the reliability and security of the module.

Installation

Install this module using pnpm, npm, or yarn:

pnpm

pnpm add @jamilservices/sb-module-router

yarn

npm install @jamilservices/sb-module-router

yarn

yarn add @jamilservices/sb-module-router

[!NOTE] This will add the @jamilservices/sb-module-router as a development dependency in your project.

ESM Import Module

CDN:

You can use the following CDN links to include the module:

https://cdn.skypack.dev/@jamilservices/sb-module-router@latest/lib/main.min.js

https://cdn.jsdelivr.net/npm/@jamilservices/sb-module-router@latest/lib/main.min.js

https://unpkg.com/@jamilservices/sb-module-router@latest/lib/main.min.js

Usage

Importing the Module

  • From install (pnpm/npm/yarn):
import { RouterModule } from '@jamilservices/sb-module-router';
  • From CDN:
import { RouterModule } from 'https://cdn.jsdelivr.net/npm/@jamilservices/sb-module-router@latest/lib/main.min.js';

Creating/Retrieving the Router Instance

const router = RouterModule.instance();

Subscribe to Router Events

router.events.subscribe({
    id: "uniqueListenerId",
    fn: data => console.log("Router data:", data)
});

Unsubscribe from Router Events

router.events.unsubscribe("uniqueListenerId");

Register a Route

router.register("home");

OR

router.register({
    id: "home",
    title: "Test Home Router Title"
});

UnRegister a Route

router.unregister("home");

Redirect a Route

router.register({
    id: "404",
    redirect: "home"
});

Navigate to a Route

router.navigate("home");

Get the Current and Previous Route

router.state();

API Documentation

RouterModule.instance({home: string, prefix: string}): SimplyBuilderRouterInterface

  • Description: Creates/retrieves and returns a new/existing router instance.
  • Object propertie:
    • home: Optional - Default route for the application. Defaults to / if not specified.
    • subpath: Optional - If set to true the root path is considered as "./", default is "/".
    • prefix: Optional - A prefix to include between the route and the hash.

instance.state(): Object

  • Description: Returns an object with the keys: current and previous.

instance.navigate(id: string): Boolean

  • Description: Navigates to a registered route.

instance.register(id: string| {id: string, title: string, redirect: string}): Boolean

  • Description: Registers a route using either a string or an object for more options.
  • Object Properties:
    • id: Required - URL route, e.g., "home" or "contact".
    • title: Optional - Title to set if the route is called successfully.
    • redirect: Optional - Internal route redirection for internal and/or SEO purposes.

instance.unregister(id: string): Boolean

  • Description: Removes a registered route for maintenance or private purposes.

instance.events.subscribe({id: string, fn: function}): Void

  • Description: Subscribes to router events.
  • Evemt Data: Returns an object with the id property (event identifier values router-update or not-found) and target, which is the registered ID of the final route.
  • Object Properties:
    • id: Required - Unique identifier for the function receiving the event.
    • fn: Required - Function that will receive the event.

instance.events.unsubscribe(id: string): Boolean

  • Description: Unsubscribes from router events for the given ID.

Contribution Guidelines

Interested in contributing? We welcome your contributions to enhance the frontend capabilities of @jamilservices/sb-module-router.
Please check our Contribution Guidelines for more details.

License

@jamilservices/sb-module-router is available under the MIT License by @jamilservicos.

  • You are free to modify and reuse the code.
  • The original license must be included with copies of this software.
  • We encourage linking back to this repository if you use a significant portion of the source code.