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

@wearethreebears/next-named-routes

v0.1.0

Published

Type-safe named routes for Next.js.

Downloads

80

Readme

@wearethreebears/next-named-routes

Type-safe named routes generated from explicit names in Next.js App Router pages. It does not require Next.js' typedRoutes option.

Install

pnpm add @wearethreebears/next-named-routes

Wrap the application's Next config:

// next.config.ts
import type { NextConfig } from "next";
import { withNamedRoutes } from "@wearethreebears/next-named-routes/plugin";

const nextConfig: NextConfig = {};

export default withNamedRoutes(nextConfig);

Name pages

Add a non-exported literal route declaration to each page.tsx:

const route = "guest.login";

export default function LoginPage() {
  return <main>Log in</main>;
}

The declaration must not be exported. Next.js does not allow arbitrary named exports from App Router pages. If an unused-variable lint rule reports the marker, disable that rule for the declaration.

Names are explicit and do not have to mirror the folder structure. They must be unique dot-separated identifiers. Dynamic parameter names still come from the folder structure:

app/
  (guest)/
    login/page.tsx                         const route = "guest.login"
  (auth)/
    page.tsx                               const route = "auth"
    subscriptions/
      page.tsx                             const route = "auth.subscriptions"
      [subscriptionId]/
        page.tsx                           const route = "auth.subscriptions.id"
        plans/[planId]/page.tsx            const route = "auth.subscriptions.plans.id"

Pages without a name fail generation by default. Set requireRouteName: false to omit unnamed pages from the generated router.

Use named routes

The plugin generates routes.generated.ts next to the app directory. Import its route function from application code:

import { route } from "./routes.generated";

route("guest.login");
route("auth");
route("auth.subscriptions");
route("auth.subscriptions.id", { subscriptionId });
route("auth.subscriptions.plans.id", { subscriptionId, planId });

Route names are a generated string-literal union. Parameters are inferred from the corresponding dynamic segments, including catch-all and optional catch-all segments.

Query parameters and hashes

For static routes, pass config after the name:

route("guest.login", {
  query: { returnTo: "/account", ref: ["email", "welcome"] },
  hash: "form",
});

For dynamic routes, path parameters and config are separate objects:

route(
  "auth.subscriptions.plans.id",
  { subscriptionId, planId },
  {
    query: { trial: true },
    hash: "pricing",
  },
);

Query values can be strings, numbers, booleans, null, undefined, or arrays of those values. URLSearchParams and arrays of key-value pairs are accepted as well. undefined values are omitted and array values become repeated query parameters.

Plugin options

Pass options as the second argument to the config wrapper:

export default withNamedRoutes(nextConfig, {
  appDir: "src/app",
  output: "src/lib/routes.generated.ts",
  extensions: ["tsx", "ts", "jsx", "js", "mdx"],
  requireRouteName: true,
});

The plugin scans app or src/app when the Next config loads and watches the directory during development. It honors pageExtensions from the Next config when extensions is not set explicitly.

Development

pnpm install
pnpm check

pnpm check runs strict TypeScript checks, compile-time API assertions, the package build, and the route generator/runtime tests.