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

@xavierapp/router

v1.0.2

Published

A complete end to end package made for handling complexity of routing of react application

Readme

@tirth_jasoliya/router

⚡ A type-safe, DX-first routing utility built on top of React Router. Inject routes once — unlock typed navigation, preloadable links, and end-to-end IntelliSense across your application.


📦 Installation

# Using npm
npm install @tirth_jasoliya/router

# Using yarn
yarn add @tirth_jasoliya/router

🚀 Why @tirth_jasoliya/router?

  • Type-safe navigation — compile-time validation of Link, NavLink, Navigate, and custom navigation hooks.
  • 🌐 Typed path + query builder — intelligent generation of URLs with strict param enforcement.
  • ⚛️ Pluggable Components & Hooks — generate your own TypedLink, useTypedNavigate, etc. with route schema inference.
  • 🧠 Preload-powered routing — enables faster UX with built-in preloading on hover, focus, or mount.
  • 🧰 Utility-first — inject once, consume anywhere. All features are composable and optimized for performance.

🧩 Core Concepts

1. 📥 Injecting Routes

Preapre your routes once in routes.tsx

// routes.ts
import { TypedRouteObject } from "@tirth_jasoliya/router";

const routes = [
  {
    element: <AuthLayout />,
    children: authRoutes,
    hydrateFallbackElement: <Loader />,
    errorElement: <ErrorComponent />
  },
  {
    element: <AppLayout />,
    children: appRoutes,
    hydrateFallbackElement: <Loader />,
  }
] as const satisfies readonly TypedRouteObject[];

export default routes

2. 📥 Injecting Routes into RouterProvider

// main.tsx
import { toRouteObjects } from '@tirth_jasoliya/router'
import { createBrowserRouter, RouterProvider } from 'react-router'

const router = createBrowserRouter(toRouteObjects(routes))

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <RouterProvider router={router} />
  </StrictMode>
)

3. 🧠 Creating Typed Components & Hooks

// lib/typed-router.ts
import { createTypedComponents, createTypedHooks, FlattenRoutes } from "@tirth_jasoliya/router";
import routes from "@/routes";

export type AppRoutes = FlattenRoutes<typeof routes> | "#";

export const { TypedLink, TypedNavLink, TypedNavigate } = createTypedComponents<AppRoutes>();

export const useTypedNavigate = createTypedHooks<AppRoutes>()

4. 🧵 Typed Navigation

function ProfileButton() {
  const { typedNavigate } = useTypedNavigate();

  return (
    <button
      onClick={() => typedNavigate("/profile/:userId", {
        params: { userId: "99" },
        query: { tab: "activity" },
        preload: true
      })}
    >
      View Profile
    </button>
  );
}

5. 🔗 Typed Link & NavLink

<TypedLink
  to="/profile/:userId"
  routeOptions={{
    params: { userId: "123" },
    query: { ref: "email" },
    preload: true,
    preloadOn: "hover"
  }}
>
  Go to Profile
</TypedLink>

<TypedNavLink
  to="/dashboard"
  className={({ isActive }) => isActive ? "active" : ""}
>
  Dashboard
</TypedNavLink>

6. 🔄 Typed Redirect / Navigate

<TypedNavigate
  to="/dashboard"
  routeOptions={{ query: { from: "login" } }}
  replace
/>

7. 🌐 buildPath + preloadRoute

import { buildPath, preloadRoute } from "@tirth_jasoliya/router";

const href = buildPath("/profile/:userId", { userId: "42" }, { ref: "twitter" });
await preloadRoute(href);

🧪 Example with React Router

import { RouterProvider, createBrowserRouter } from "react-router-dom";
import { toRouteObjects, getRoutes } from "@tirth_jasoliya/router";

const router = createBrowserRouter(toRouteObjects(getRoutes()));

<RouterProvider router={router} />

⚙️ Utility Functions

| Function | Description | | -------------------- | ---------------------------------------------- | | injectRoutes() | Injects your static route config | | getRoutes() | Returns injected routes | | getRouteMeta(path) | Fetches route metadata for a given path | | buildPath() | Builds a typed path with optional params/query | | preloadRoute() | Triggers preload for the given path | | toRouteObjects() | Converts typed routes to RouteObject[] |


📐 Type Utilities

| Type | Description | | ------------------------------ | ---------------------------------------- | | PathParams<"/user/:id"> | { id: string } | | QueryParams<{ key: string }> | { key: string } | | FlattenRoutes<Routes> | Extracts all deep route paths as a union | | TypedNavigateTarget<T> | Supports path strings, object, or number | | TypedNavigateOptions<T> | Navigation options type-safe per path |


💡 Roadmap

  • ✅ React Router v6+ support
  • 🔜 SSR-friendly hooks (Next.js / RSC layer)
  • 🔜 Tree-shakable route resolver plugins
  • 🔜 CLI schema-to-types generator

👨‍💻 Contributing

Feel free to open issues, request features, or submit PRs. Let’s redefine typed routing together.


📄 License

MIT — Built by [Tirth Jasoliya] with passion, precision, and preloading.