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-router-light

v1.1.1

Published

Lighter version of react-router with easy to use and integrate with added features like middleware.

Downloads

8

Readme

react-router-light

Lighter version of react-router with easy to use and integrate with added features like middleware.

Source is in ./src

Install

With npm

npm install --save react-router-light

with yarn

yarn add react-router-light

using

Router is to set to manage the children Route Router accepts the loadingUI, homePath and notFoundUI

loadingUI is a component which is used for Route to render as chunks and provides a UX. homePath is setting the default path if no path is available default is '' notFoundUI can be either component or element. This will be displayed when a page is not found in the Route specified path's

Route is a component which maintains individual routes Route accepts the path, redirectIfNotSatisfied, middleware, element, component and children

path is string which denote's in which path we can access the component or element. You can params key to path by the colon (:) like '/route/:key' here key will be the key to the param. You can pass n number of params. middleware is array of functions, function or a boolean value which deals with checking if this page can be accessible or not. redirectIfNotSatisfied is a string path which will redirect if middleware conditions are not satisfied. component is React component which can be render if mounts on specified path. It can be lazy loaded or normal component. If we lazy loading is used loadingUI in Router is displayed while fetching the chunks of the component. element or children both or elements. If component, element and children are passed first it try to load component if not element and in last children.

Hooks There are useParams, useNavigate, useQueryParams, useBrowserState available.

useParams will fetch the values params available in the current path. useQueryParams will fetch search params or hash params available in the current location. useBrowserState will fetch the browser state that is set. useHash will fetch the hash that is set (if it string set other vise it will converted to queryParams) useNavigate used to redirect user to specific path. It hash redirect and back functions available useRouteUpdater used to set different location params it has setQueryParams, setHash and setBrowserState functions

redirect accepts to and object of state, hash, search keyed values like

const navigate = useNavigate()
navigate.redirect(to, {state, hash, search})

using useRouteUpdater

const {setQueryParams, setHash, setBrowserState} = useRouteUpdater()
// setHash accepts only string
// setQueryParams accept object 
// setBrowserState accepts object

here search and hash (if hash is object) objects with key value pairs or queryParams.

Using outside the hooks and components

getParams
onCurrentPathnameUpdate
onQueryParamUpdate

queryParams
currentPathname

In this queryParams and currentPathname can be used to retrieve and set the values based on this paths redirection changes.

currentPathname can be use to redirect by setting the value in it. It can be only string. queryParams will return query params as a object and set the vales as object it will set the search query to browser.

And onCurrentPathnameUpdate, onQueryParamUpdate can be used to trigger the this functions if currentPathUpdates adn currentPathnameUpdates adn queryParamsUpdate. And this will return the function which can be called if there is not more use to inside function. This takes callback function as argument.

usage

const returnFunction = onCurrentPathnameUpdate(() => {
    ...
})

returnFunction()