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

gb-react-router

v1.0.5

Published

A type safe React routing library for SPA built with Typescript and React

Downloads

10

Readme

React Router Components

A collection of React components for building a simple router in your React application. These components provide client-side routing functionality.

Components

Link

The Link component is used for creating hyperlinks that navigate within the application without a full page refresh. It is enhanced with strict TypeScript typings.

Usage

import Link from "./Link";

// Usage within your component
<Link to="/path">Link Text</Link>

Here's the updated documentation for the Route functional component in Markdown format:

Route

The Route component renders its children, a specified functional component, or an element based on the current URL path. It throws an error if multiple rendering options are provided simultaneously.

Props

  • path (required): A string representing the URL path to match for rendering.
  • children (optional): Content to render when the path matches the current URL.
  • component (optional): A function that returns content to render when the path matches the current URL.
  • element (optional): An element to render when the path matches the current URL.

Usage

The Route component allows you to define different rendering options based on the URL path.

  • Usage with children:
import Route from "./Route";

// Usage within your component
<Route path="/path">
  {/* Content to render when the path matches */}
</Route>
  • Usage with component:
import Route from "./Route";

// Define a functional component to render
const MyComponent = () => {
  // Your component logic here
  return <div>Component Content</div>;
};

// Usage within your component
<Route path="/path" component={MyComponent} />
  • Usage with element:
import Route from "./Route";

// Define an element to render
const myElement = <div>Element Content</div>;

// Usage within your component
<Route path="/path" element={myElement} />
// Or
<Route path="/path" element={<div>Element Content</div>} />

The Route component ensures that only one of the rendering options (children, component, or element) is provided. If multiple options are specified, it will throw an error to prevent ambiguity.

Exported Types:

  • RouteProps: The type definition for the Route component's props, including path, children, component, and element.

You can import the Route component and its associated type like this:

import Route, { RouteProps } from "./Route";

This allows you to use the Route component and RouteProps type in other parts of your application while maintaining clarity and type safety.

BrowserRouter

The BrowserRouter component combines the RouterProvider, Router, and your application components for easy setup. It is the top-level component that should wrap your entire application. Strict TypeScript typings are added.

Usage

import { BrowserRouter } from "./BrowserRouter";

// Usage at the root of your application
<BrowserRouter>
  <!-- Your application components -->
</BrowserRouter>

Installation

You can install these components using npm or yarn:

npm i gb-react-router

License

This project is licensed under the MIT License - see the LICENSE file for details.

gb-react-router

gb-react-router