porpoise-router
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

porpoise-router

A framework-agnostic, standalone router, designed for use with Web Components

Initialize JS:

/* Initialize the router */
import { createRouter } from "porpoise-router";

const router = createRouter("root", {
    // path "/" renders 
    // <index-view></index-view>
    "/": "index-view", 

    // path "/about" renders 
    // <about-view></about-view>
    "/about": "about-view", 

    // path "/profile/:userId" renders 
    // <profile-view></profile-view>
    // "userId" access via (router.current.params.userId)
    "/profile/:userId": "profile-view",
});

Initialize HTML:

<p-router name="root"></p-router>

Porpoise Integration (Optional):

import * as Porpoise from "porpoise";

// Allow access to the router:
Porpoise.globalize("router", () => router);

// Access the router in porpoise elements via this.$globals.router:
Porpoise.construct({
    /* your component... */
    events: {
        click() {
            this.$globals.router.push("/about");
        }
    }
})

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i porpoise-router

    Weekly Downloads

    2

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    60.6 kB

    Total Files

    22

    Last publish

    Collaborators

    • raghavm