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

@real-router/browser-plugin

v0.17.1

Published

Browser integration plugin with History API, hash routing, and popstate support

Readme

@real-router/browser-plugin

npm npm downloads bundle size License: MIT

Browser History API integration for Real-Router. Synchronizes router state with browser URL and handles back/forward navigation.

Installation

npm install @real-router/browser-plugin

Peer dependency: @real-router/core

Quick Start

import { createRouter } from "@real-router/core";
import { browserPluginFactory } from "@real-router/browser-plugin";

const router = createRouter([
  { name: "home", path: "/" },
  { name: "users", path: "/users/:id" },
]);

router.usePlugin(browserPluginFactory());
await router.start(); // path inferred from browser location

Options

router.usePlugin(
  browserPluginFactory({
    base: "/app", // Base path prefix for all routes
    forceDeactivate: true, // Bypass canDeactivate guards on back/forward
  }),
);

| Option | Type | Default | Description | | ----------------- | --------- | ------- | ---------------------------------------------------------------------- | | base | string | "" | Base path for all routes (e.g., "/app" → URLs start with /app/...) | | forceDeactivate | boolean | true | Bypass canDeactivate guards on browser back/forward |

Hash routing? Use @real-router/hash-plugin instead.

Router Extensions

The plugin extends the router instance with three methods via extendRouter():

| Method | Returns | Description | | ----------------------------------------------------- | -------------------- | ---------------------------------------------------------------------------------------------------- | | buildUrl(name, params?, options?: { hash? }) | string | Build full URL with base path. options.hash (decoded) is encoded and appended. | | matchUrl(url) | State \| undefined | Parse URL to router state | | replaceHistoryState(name, params?, options?: { hash? }) | void | Update browser URL without triggering navigation. Tri-state hash: undefined preserves, "" clears, value sets. |

router.buildUrl("users", { id: "123" });
// => "/app/users/123" (with base "/app")

router.matchUrl("/app/users/123");
// => { name: "users", params: { id: "123" }, path: "/users/123" }

// Update URL silently (no transition, no guards)
router.replaceHistoryState("users", { id: "456" });

buildUrl vs buildPath

router.buildPath("users", { id: 1 }); // "/users/1"       — core, no base
router.buildUrl("users", { id: 1 }); // "/app/users/1"   — plugin, with base

replaceHistoryState vs navigate({ replace: true })

router.replaceHistoryState(name, params); // URL only, no transition
router.navigate(name, params, { replace: true }); // Full transition + URL update

URL Fragment ("hash") Support

browser-plugin ships first-class URL-fragment support: <Link hash> from any framework adapter, programmatic router.navigate(name, params, { hash }), and a state.context.url = { hash, hashChanged } namespace populated on every transition.

// Programmatic — tri-state opts.hash
router.navigate("settings", {}, { hash: "profile" }); // set
router.navigate("settings", {}, { hash: "" });        // clear
router.navigate("settings");                          // preserve current

// In subscribers
router.subscribe(({ route }) => {
  console.log(route.context.url?.hash);        // "profile"
  console.log(route.context.url?.hashChanged); // true on hash-only nav
});

See the Hash Fragment Support wiki page for the full surface (encoding, F5 priming, hash-aware active state).

Navigation Source (state.context.browser.source)

On every successful transition the plugin tags state.context.browser with the trigger origin — use this in subscribe handlers to distinguish back/forward from programmatic navigation:

router.subscribe(({ route }) => {
  if (route.context.browser?.source === "popstate") {
    // back/forward button — restore scroll, skip analytics "view" event, ...
  } else {
    // router.navigate()/router.start() — programmatic
  }
});

Both values are frozen singletons, so object-identity comparison is safe and zero-allocation.

| Value | Meaning | | ----------- | ------------------------------------------------------------- | | "navigate" | Triggered by router.navigate(), router.start(), or replaceHistoryState() | | "popstate" | Triggered by browser back/forward buttons (popstate event) |

Form Protection

Set forceDeactivate: false to respect canDeactivate guards on back/forward:

router.usePlugin(browserPluginFactory({ forceDeactivate: false }));

import { getLifecycleApi } from "@real-router/core/api";

const lifecycle = getLifecycleApi(router);
lifecycle.addDeactivateGuard(
  "checkout",
  (router, getDep) => (toState, fromState) => {
    return !hasUnsavedChanges(); // false blocks back/forward
  },
);

SSR Support

The plugin is SSR-safe — createSafeBrowser detects the absence of window/history and swaps the History API calls (pushState, replaceState, addPopstateListener, getLocation, getHash) for warn-once no-ops. Pure URL helpers are environment-agnostic and behave identically on the server:

// Server-side — no crashes, History API calls become no-ops
router.usePlugin(browserPluginFactory({ base: "/app" }));

router.buildUrl("home");           // "/app/home" — base is still applied
router.matchUrl("/app/users/123"); // { name: "users", params: { id: "123" }, path: "/users/123" }
await router.start("/app/home");   // transitions normally; no popstate subscription

The first call to any History API method emits a one-time console warning so accidental SSR usage is visible without spamming logs.

Documentation

Full documentation: Wiki — browser-plugin

Related Packages

| Package | Description | | -------------------------------------------------------------------------------------- | -------------------------------------- | | @real-router/core | Core router (required peer dependency) | | @real-router/hash-plugin | Hash-based routing (#/path) | | @real-router/react | React integration | | @real-router/logger-plugin | Development logging |

Contributing

See contributing guidelines for development setup and PR process.

License

MIT © Oleg Ivanov