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

react-typed-router

v0.0.1

Published

## Why

Downloads

3

Readme

React Typed Router

Why

Because routes should be typed by its required props. With this router, you don't have to remember each route's props anymore, they will be statically checked by the power of typescript.

Params

All dynamic parameters will be in url search string.

Path

A specific route can only have a single static path. PARAMETER IN PATHNAME IS WRONG!

How

import {makeRouter,makeRoute,makeRouteWithParams} from "react-typed-router"
import {createBrowserHistory} from "history"

const historyInstance = createBrowserHistory()

const appRouter = makeRouter(historyInstance)

const route1 = makeRoute({
    key:"/route1",
    component:()=>import("../route1")
})

const route2 = makeRouteWithParams({
    key:"/route2",
    component:()=>import("../route2")
},['param1']) // only param1 will be passed from url search to route2 as its props.

const subroute = makeRoute({
    key:"/route1/subroute",
    component:()=>import("../route1/subroute")
},route1)

appRouter.init([
    route1,
    route2,
    // only pass root routes here.
])

function goToSubRoute(){
    appRouter.pushHistory(subroute)
}

function goToRoute2(){
    appRouter.pushHistory(route2,{
        /**
         *   here is why you should use this router:
         *   if u r using typescript, and route2's default export is a stateless component with Props: {param1: "a"|"b" }
         *   then it will prevent any illegal param when you use pushHistory. 
         */
        param1: "some params"
    })
}

function pushParams(){
    appRouter.pushParams({
        someParam:"someParam"
    })
}

function App(){
    return <div>
        <nav>
            <ul>
                <li>
                    <a onClick={goToRoute2} href={appRouter.createHref(route2,{param1:"someParam"})}></a>
                </li>
            </ul>
        </nav>
        <div id="content">
            <appRouter.Router /> 
        </div>
    </div>
}