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

mobx-route

v2.1.2

Published

Simple and lightweight typed router

Readme

mobx-route

NPM version build status npm download bundle size

🚀 Simple and lightweight typed MobX router 🚀 Uses path-to-regexp power for path matching

📖 Read the docs →


Quick Start

import { createRoute } from "mobx-route";

const userDetails = createRoute("/users/:id");

// Path params are required — TypeScript enforces it
await userDetails.open({ id: 1 });

userDetails.isOpened; // true
userDetails.params;   // { id: "1" } — fully typed

✨ Features

🔗 Nested Routes with .extend()

Build route trees naturally — no config arrays, no <Routes> wrappers:

const users = createRoute("/users");
const userDetails = users.extend("/:userId");
const userPhotos = userDetails.extend("/photos");

// Path is auto-concatenated: /users/:userId/photos
await userPhotos.open({ userId: 42 });
// → /users/42/photos

users.isOpened;        // true (parent is open too)
users.hasOpenedChildren; // true

🛡️ Route Guards & Redirects

Protect routes with beforeOpen — cancel navigation or redirect:

const dashboard = createRoute("/dashboard", {
  beforeOpen: async () => {
    if (!await isAuthenticated()) {
      return { url: "/login", replace: true }; // redirect
    }
    // return undefined → proceed
  },
  checkOpened: () => currentUser.isAuthorized, // reactive predicate
});

🔮 Virtual Routes for Modals & Drawers

Same .open() / .close() / .isOpened API — but no URL involved:

const authModal = createVirtualRoute({
  checkOpened: (route) => route.query.data.modal === "auth",
  open: (_, route) => route.query.update({ modal: "auth" }),
  close: (route) => route.query.update({ modal: undefined }),
  beforeClose: () => !hasUnsavedChanges, // prevent closing
});

authModal.isOpened;  // reactive — auto-updates from query
authModal.isClosing; // for exit animations

🎯 Typed Query Params

const search = createRoute<
  "/search",
  {},
  {},
  { q: string; page?: number; sort?: "asc" | "desc" }
>("/search");

// TQueryParams types the INPUT — what you pass to open()
await search.open({}, { query: { q: "mobx", page: 1 } });

// query.data is always Record<string, string> at runtime (values come from URL)
search.query.data.q;    // string
search.query.data.page; // string | undefined — use Number() or QueryParam for typed access

🔄 update() for In-Place Changes

Replace params without polluting browser history:

await userRoute.open({ userId: 1 }, { query: { tab: "profile" } });
await userRoute.update({ userId: 2 });
// → /users/2?tab=profile (replace: true, mergeQuery: true by default)

🧩 React Integration

import { RouteView, RouteViewGroup, Link } from "mobx-route/react";

// Declarative route rendering
<RouteView route={userRoute} view={UserPage} fallback={<Loading />} />

// Route switching with fallback
<RouteViewGroup otherwise={notFoundRoute}>
  <RouteView route={homeRoute} view={HomePage} />
  <RouteView route={userRoute} view={UserPage} />
  <div>Not found</div>
</RouteViewGroup>

// Type-safe links
<Link to={userRoute} params={{ userId: 42 }}>Profile</Link>

🧠 View Model Integration

import { RouteViewModel } from "mobx-route/view-model";

class UserPageVM extends RouteViewModel<typeof userRoute> {
  route = userRoute;
  // payload, pathParams, query, isMounted — all built-in
}

🌍 Optional Path Segments & Wildcards

// Optional segment
const route = createRoute("/users{/:tab}");
route.open();          // → /users
route.open({ tab: 1 }); // → /users/1

// Wildcard/rest params
const docs = createRoute("/docs/*rest");
docs.open({ rest: ["api", "v2", "auth"] }); // → /docs/api/v2/auth

📦 Tree-Shakeable Subpath Exports

Only pay for what you use:

import { createRoute } from "mobx-route";              // core only
import { RouteView, Link } from "mobx-route/react";    // + React
import { RouteViewModel } from "mobx-route/view-model"; // + VM

Installation

npm install mobx-route
# or
pnpm add mobx-route
# or
yarn add mobx-route

Peer dependencies (React integration is optional):

npm install mobx
# For React:
npm install mobx-react-lite react react-dom

Contribution Guide

Want to contribute? Follow this guide


License

MIT