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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-router-ctx

v0.1.1

Published

A React routing solution that replicates the familiar react-router API using React Context to store and manage the current route internally. Enables flexible routing without relying on browser history or URL changes.

Readme

react-router-ctx

A lightweight, zero-dependency React router that replicates the familiar react-router API using React Context. This package enables flexible, in-memory routing for React applications—ideal for environments where you don't want to rely on browser history or URL changes (e.g., embedded apps, modals, or testing).

Features

  • Familiar API: Components like <ContextRouter>, <Routes>, <Route>, <Link>, and <Outlet>.
  • Context-based Routing: Stores and manages the current route using React Context, not browser history.
  • Parameter & Wildcard Support: Route patterns support parameters (:id) and wildcards (*).
  • TypeScript Support: Fully typed API for safer development.
  • No External Dependencies: Only requires React as a peer dependency.

Installation

npm install react-router-ctx

Usage

import { ContextRouter, Routes, Route, Link, Outlet } from 'react-router-ctx';

function App() {
  return (
    <ContextRouter>
      <Routes>
        <Route path="/fizz/*" element={<AppLayout />}>
          <Route path="/" element={<Home />} />
          <Route path="/about" element={<About />} />
          <Route path="/users/:id" element={<UserDetail />} />
        </Route>
      </Routes>
    </ContextRouter>
  );
}

function AppLayout() {
  return (
    <>
      <Navbar />
      <Outlet />
    </>
  );
}

function Home() {
  return (
    <div>
      <h1>Home</h1>
      <Link to="/about">About</Link>
    </div>
  );
}

API

Components

- <ContextRouter>

  • Provides routing context for its children.

  • Props:

    • basePath?: string – Optional initial path (default: /).
    • children: A single <Routes> element.

- <Routes>

  • Renders the first matching <Route> child for the current path.

- <Route>

  • Props:

    • path: string – Route pattern (supports parameters and wildcards).
    • element?: ReactNode – The component to render.
    • children?: <Route>[] – Nested routes.

- <Link>

  • Props:

    • to: string – Path to navigate to.
    • Other anchor props.

- <Outlet>

  • Renders nested routes inside a parent <Route>.

Hooks

  • useRouter() – Access { path, navigate } from context.
  • useParams() – Get route parameters as an object.

Example

import { useParams } from 'react-router-ctx';

function UserDetail() {
  const params = useParams();
  return <div>User ID: {params.id}</div>;
}

When to Use

  • In-memory navigation (modals, wizards, embedded apps)
  • Testing React components with routing
  • Apps where you don't want to manipulate the browser URL

Limitations

  • Does not sync with browser history or URL.
  • Not a drop-in replacement for react-router in all scenarios.

License

This Project is licensed under the MIT license

Contributing

Contributions, issues, and feature requests are welcome!

https://github.com/rarescovei5/react-router-ctx