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

named-react-router

v1.3.2

Published

A lightweight extension to React Router for named routes

Readme

named-react-router

A lightweight extension to React Router that provides named routes for simpler, more maintainable navigation.

Features

  • Named navigation with path parameters and query support
  • Hooks for easy programmatic navigation (useNamedNavigate) and route-awareness (useNamedLocation)
  • Nested routes just like React Router, but with named references
  • Declarative route definition – Use <NamedRoutes> and <NamedRoute> for JSX-based routing setup.
  • Nested routes support – Define structured, hierarchical routes with named references.

Installation

Install named-react-router along with react-router-dom (which it depends on):

npm install named-react-router react-router-dom

Or, with Yarn:

yarn add named-react-router react-router-dom

Usage

Create a Named Router

Use createNamedBrowserRouter to define your routes as an array of NamedRouteObject:

import { createNamedBrowserRouter } from "named-react-router";
import HomePage from "./HomePage";
import AboutPage from "./AboutPage";
import TeamPage from "./TeamPage";

enum RouteNames {
  home = "home",
  about = "about",
  team = "team",
}

export const router = createNamedBrowserRouter([
  {
    path: "",
    name: RouteNames.home,
    element: <HomePage />,
    children: [
      {
        path: "about",
        name: RouteNames.about,
        element: <AboutPage />,
        children: [
          { path: "team", name: RouteNames.team, element: <TeamPage /> },
        ],
      },
    ],
  },
]);

Then wrap your app with the returned router (similar to a standard React Router setup).

Declarative Routing with <NamedRoutes>

Alternatively, use the <NamedRoutes> and <NamedRoute> components for a JSX-based route definition.

import { NamedRoutes, NamedRoute } from "named-react-router";
import HomePage from "./HomePage";
import AboutPage from "./AboutPage";
import TeamPage from "./TeamPage";
import { BrowserRouter } from "react-router-dom";

export function App() {
  return (
    <BrowserRouter>
      <NamedRoutes>
        <NamedRoute name="home" path="/" element={<HomePage />}>
          <NamedRoute name="about" path="about" element={<AboutPage />}>
            <NamedRoute name="team" path="team/:id" element={<TeamPage />} />
          </NamedRoute>
        </NamedRoute>
      </NamedRoutes>
    </BrowserRouter>
  );
}

Navigate by Name

Use the useNamedNavigate hook to navigate by route name instead of manually typed paths:

import { useNamedNavigate } from "named-react-router";

export function GoToTeamButton() {
  const navigate = useNamedNavigate();

  function handleClick() {
    navigate({ name: "team" }); // Navigates to "about/team" based on the example above
  }

  return <button onClick={handleClick}>Go To Team</button>;
}

Access the Named Location

Note: useNamedLocation() does not currently work with <NamedRoutes>. Use createNamedBrowserRouter

Use the useNamedLocation hook to get the current location plus an optional name property:

import { useNamedLocation } from "named-react-router";

export function Breadcrumb() {
  const location = useNamedLocation();
  const routeName = location.name || "Unnamed Route";

  return (
    <div>
      <p>Current Path: {location.pathname}</p>
      <p>Current Named Route: {routeName}</p>
    </div>
  );
}

API Reference

createNamedBrowserRouter(routes, options)

Creates a React Router browser router with named-route capabilities.

  • routes – An array of NamedRouteObject (extends React Router’s RouteObject with name and optional nested children).
  • options – Optional configuration, same as the options in createBrowserRouter.

useNamedNavigate()

Returns a function to navigate by name or by standard path.

const navigate = useNamedNavigate();

navigate("some/path");
// or
navigate({
  name: RouteNames.team,
  params: { id: "123" },
  query: { tab: "info" },
});

useNamedLocation()

Only works with createNamedBrowserRouter. Returns the standard location object plus a name property for the active named route.

const location = useNamedLocation();

console.log(location.pathname); // "/about/team/123"
console.log(location.name); // "team"

<NamedRoutes/>

A wrapper component that replaces and enables named-route navigation. It automatically collects named route definitions for use with useNamedNavigate().

import { NamedRoutes, NamedRoute } from "named-react-router";

<NamedRoutes>
  <NamedRoute name={RouteNames.home} path="/" element={<HomePage />} />
  <NamedRoute name={RouteNames.about} path="about" element={<AboutPage />} />
</NamedRoutes>;

<NamedRoute/>

A component that defines a named route inside .

Props:

  • name (string) – The unique name of the route. Required for named navigation.
  • path (string) – The path of the route.
  • element (ReactNode) – The component to render at this route.
<NamedRoute
  name={RouteNames.profile}
  path="profile/:id"
  element={<ProfilePage />}
/>