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

@steal-like-a-dev/react-router

v1.0.11

Published

Minimalist implementation of the popular react-router package.

Downloads

2

Readme

react-router | steal-like-a-dev

Minimalist implementation of react-router. Primarily for teaching purposes in my StealLikeADev.com tutorial series, BUT since it's actually very usable, I decided to publish it as a NPM package as well.

These docs are "stolen" from react-router, but I've left only the parts I've actually implemented. Happy stealing!

Installation & usage

$ npm install @steal-like-a-dev/react-router

import { Route, Link, Redirect, Switch } from '@steal-like-a-dev/react-router';

API

~~<BrowserRouter>~~

I specifically built just this routing method - using normal URL's instead of hashes - so no need for this component.

<Route>

Props:

  • component

A React component to render only when the location matches. It will be rendered with route props.

  • path: string | string[]

Any valid URL path or array of paths.

! Routes without a path always match.

  • exact: boolean

When true, will only match if the path matches the location.pathname exactly.

Props passed to rendered component

  • match: { params: Object }

An object with one single property - params - which contains the values of all the matched params in the pathname. For example:

<Route path="/groups/:groupId/exercise/:exerciseId" component={TextComp}></Route>

function TextComp (props) {
  return (
    <div>
      <h1> Group: {props.match.groupId} </h1>
      <p> Exercise: {props.match.exerciseId} </p>
    </div>
  )
}

will render on this path /groups/Faculty/exercise/22 an h1 with text Faculty and a <p> with text 22.

  • location: Object

location: {
    state: any,     // Current route state
    search: string, // String representation of query params
    hash: hash,     // Current location's hash
    pathname: hash  // Current pathname
},
  • history: { push: Function, replace: Function }

An object with 2 functions used for navigating to a different page.

history: {
  push(to: string, state?: any, replace?: boolean = false), // navigate forward to `to` URL, with an optional state that will be passed to the next route.
  
  replace(to: string, state?: any) // navigate to `to` URL by replacing the current location in the navigation stack.
}

<Link>

Props:

  • to: string

A string representation of the Link location, created by concatenating the location’s pathname, search, and hash properties.

  • to: object

An object that can have any of the following properties:

to: {
  pathname: string, // A string representing the path to link to
  search: string,   // A string representation of query parameters
  hash: string,     // A hash to put in the URL, e.g. #a-hash
  sate: any         // State to persist to the location
}
  • to: function

A function to which current location is passed as an argument and which should return location representation as a string or as an object

  • replace: boolean

When true, clicking the link will replace the current entry in the history stack instead of adding a new one.

<Redirect>

  • to: string

The URL to redirect to

  • to: object

to: {
  pathname: string, // A string representing the path to link to
  search: string,   // A string representation of query parameters
  hash: string,     // A hash to put in the URL, e.g. #a-hash
  sate: any         // State to persist to the location
}
  • push: bool

When true, redirecting will push a new entry onto the history instead of replacing the current one.

  • from: string

Only redirect when on this current pathname.

  • exact: bool

This can only be used in conjunction with from to exactly match a location from which to redirect.

<Switch>

Renders the first <Route> or <Redirect> that matches the location.

How is this different than just using a bunch of <Route>s?

<Switch> is unique in that it renders a route exclusively. In contrast, every that matches the location renders inclusively.

Test project

As you can see, there's also a test project included in this repo. You can run it with

npm run test:dev

or

npm run test:prod

Further development & bugfixing

I won't be developing this library any futher because, well... there's already the original out there. But I'll be fixing bugs regarding features already implemented.