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 🙏

© 2026 – Pkg Stats / Ryan Hefner

th12router

v1.0.3

Published

React Router

Readme

Simple React Router

You can use this router for both React web applications and React Native.

Warning: If your npm version not supported peerDependencies. You should install th12storage. "npm install th12storage".

Getting Started

Simple example (React Web).

    import { Router, Link, useParams, usePath } from "th12router";

    // Main component
    function Home(){
        return  <div>
                    Home
                </div>;
    }

    function App() {
        // Description of routes
        let routes = [
            {"path": "/", "component": Home, "private": null}
        ];
        
        // Return JSX
        return (
            <div className="App">
                <Router routes={routes} />
            </div>
        );
    }

export default App;

Documentation

Imports:

  • Router;
  • Link;
  • useParams;
  • usePath.

Router

This is the main component. It loads all router components.

    <Router routes={routes} />

Router use routes array.

    let routes = [
        {"path": "/pagenotfound", "component": PageNotFound, "private": null},
        {"path": "/", "component": Home, "private": null},
        {"path": "/user/:id&^[0-9]+", "component": User, "private": true},
        {"path": "/lazy", "component": Lazy, "private": null}
    ];

path - This is the path by which you need to download the router. You can use params and regular expressions. For example: /user/:id&^[0-9]+ A colon indicates that a parameter is used. An Ampersand indicates that a regular expressions is used.

component - The component to be downloaded.

private - The parameter that tells whether to load the component during authorization or not. If null is specified, the component is loaded in any case.

Link

This is an interface for interacting with the router.

    <Link 
        to="/" 
        style={{"color": "red"}}
        astyle={{"color": "green"}}
        timer="1000"
        title=""
        pstate
    >To Home</Link>

Description:

  • to(path);
  • style(css style);
  • astyle(css style active link "onMouseDown event");
  • timer(delay activet link after mousedown);
  • title(browser title if set pstate);
  • pstate(history push state).

useParams

If you use parameters in a router, you can load the parameters into a component.

    let params = useParams();
    console.log(params["id"]);

usePath

A hook to get the current path.

    let path = usePath();
    console.log(path);

Additional Information

Lazy components

If you want to load lazy components. You need to use the React.Suspense component.

    const Lazy = React.lazy(() => import("./Lazy.jsx"))

    let routes = [
        {"path": "/pagenotfound", "component": PageNotFound, "private": null},
        {"path": "/", "component": Home, "private": null},
        {"path": "/user/:id&^[0-9]+", "component": User, "private": true},
        {"path": "/lazy", "component": Lazy, "private": null}
    ];
    <React.Suspense fallback={<React.Fragment>...</React.Fragment>}>
                <Router routes={routes} />
            </React.Suspense>

Initialization

    import { useStorage } from "th12storage";
    // Initial path if need
    useStorage("routerPage", window.location.pathname);
    // App auth if need
    useStorage("routerAuth", true);

Full React Web example

    import React from "react";
    import { Router, Link, useParams, usePath } from "th12router";
    import { useStorage } from "th12storage";

    // Page Not Found component
    function PageNotFound(){
        let path = usePath();
        return  <div>
                    Page not found({path})! 
                    <Link to="/" style={{"color": "red"}} pstate>To Home</Link>
                </div>;
    }

    // Main component
    function Home(){
        return  <div>
                    Home
                    <Link astyle={{"color":"green"}} to="/user/1" title="About us" pstate>Profile</Link>
                    <Link to="/lazy" pstate>To Lazy</Link>
                </div>;
    }

    // Componenet with params and regular expresion. /user/:id&^[0-9]+
    // And component with bad path. Waiting for Page Not Found component to load.
    function User(){
        let params = useParams();
        
        return  <div>
                    User {params["id"]}!
                    <Link to="/otherway" pstate>To Home</Link>
                </div>;
    }

    export default function App() {
        // Lazy load component
        const Lazy = React.lazy(() => import("./Lazy.jsx"))

        let routes = [
            {"path": "/pagenotfound", "component": PageNotFound, "private": null},
            {"path": "/", "component": Home, "private": null},
            {"path": "/user/:id&^[0-9]+", "component": User, "private": true},
            {"path": "/lazy", "component": Lazy, "private": null}
        ];

        useStorage("routerPage", window.location.pathname);
        useStorage("routerAuth", true);
        
        return (
            <div className="App">
                <React.Suspense fallback={<React.Fragment>...</React.Fragment>}>
                    <Router routes={routes} />
                </React.Suspense>
            </div>
        );
    }

Full React Native example

    import React from "react";
    import { StyleSheet, Text, View, SafeAreaView, StatusBar } from 'react-native';
    import { Router, Link, useParams, usePath } from "th12router";
    import { useStorage } from "th12storage";

    // Page Not Found component
    function PageNotFound(){
        let path = usePath();
        return  <Text>
                    Page not found({path})! 
                    <Link to="/" style={{"color": "red"}}>To Home</Link>
                </Text>;
    }

    // Main component
    function Home(){
        return  <Text>
                    Home
                    <Link astyle={{"color":"green"}} to="/user/1" title="About us" pstate>Profile</Link>
                </Text>;
    }

    // Componenet with params and regular expresion. /user/:id&^[0-9]+
    // And component with bad path. Waiting for Page Not Found component to load.
    function User(){
        let params = useParams();
    
        return  <Text>
                    User {params["id"]}!
                    <Link to="/otherway">To Home</Link>
                </Text>;
    }

    export default function App() {
        let routes = [
            {"path": "/pagenotfound", "component": PageNotFound, "private": null},
            {"path": "/", "component": Home, "private": null},
            {"path": "/user/:id&^[0-9]+", "component": User, "private": true}
        ];

        useStorage("routerPage", "/");
        useStorage("routerAuth", true);

        return (
            <SafeAreaView style={styles.safe}>
                <View style={styles.container}>
                    <Router routes={routes} />
                </View>
            </SafeAreaView>
        );
    }

    const styles = StyleSheet.create({
        safe: {
            flex: 1,
            marginTop: StatusBar.currentHeight
        },
        container: {
            flex: 1,
            backgroundColor: '#fff',
            alignItems: 'center',
            justifyContent: 'center',
        }
    });