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

@iosio/react-router

v1.0.24

Published

simple react router

Downloads

14

Readme

@iosio/react-router

Simple react-router.

Installation

npm install @iosio/react-router

Usage

See the example in the demo (/public/index.js).

useRouter

This router accepts an object where the keys represent the "/path" and the value is a component or an object with two keys: title and Route (component). The document title will be set when the route changes.

import {useRouter} from '@iosio/react-router';
const pathMap = {
    '/': {title: 'home', Route: HomePageComponent,},
    '/about': {title: 'about', Route: AboutPageComponent},
    '/docs': {title: 'docs', Route: DocsPageComponent}
}

const App = () => {
    const {Route} = useRouter({pathMap});
    return (
        <>
            <nav/>
            <main>
                <Route/>
            </main>
        </>
    )
}
  • pathMap - Object - example: { '/path': { title: 'page title', Route: Component } }

(optional)

  • fallbackPath - String - default: "/" - the default path to fallback to if no match is found

Built-in Logic:

If the user attempts to visit a page that is not on the pathMap, the router will attempt to replace history with the previously visited path, else it will navigate to "/" or the path that is defined as the fallbackPath.

Linkage

props
  • to - String
  • toParams - Object - pass an object to be stringified into query parameters
  • ...rest - rest spread to the root anchor tag element <a {...rest}/>
import {Linkage} from '@iosio/react-router';
// both go to /about?foo=bar
<Linkage to={'/about?foo=bar'}>About</Linkage>
<Linkage to={'/about'} toParams={{foo: 'bar'}}>About</Linkage>

navigate

Programmatically navigate

import {navigate} from '@iosio/react-router';
// string
navigate('/path?id=1#foo');
// object
navigate({
    pathname: '/path',

    query: '?id=1',
    // or optionally use params (Object that will be stringified)
    params: {id: 1},

    hash: '#foo'
});
// function
navigate(({pathname, query, params, hash}) => ({
    pathname,
    params: {...params, id: 2}
}));

useLocation

import {useLocation} from '@iosio/react-router';
const AboutPageComponent = () => {
    
    const [{path, pathname, query, params, hash}, navigate] = useLocation();
    
    return <h1>About</h1>
};

License

MIT