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-state-machine-router/url-persistence

v6.0.0

Published

URL persistence layer for MobX State Machine Router

Readme

@mobx-state-machine-router/url-persistence

URL synchronization for MobX State Machine Router with hash/browser history support

npm version npm downloads CI codecov license

Live Demo | GitHub

Features

  • Hash Routing — Works on any static host (GitHub Pages, S3, Netlify, etc.)
  • Browser History — Clean URLs with proper server configuration
  • Query Parameters — Automatically syncs params to URL
  • Deep Linking — Users can bookmark and share URLs
  • Back/Forward — Full browser history support
  • Custom Serializers — Handle complex types (arrays, objects, booleans)

Installation

npm install @mobx-state-machine-router/url-persistence @mobx-state-machine-router/core history mobx

Quick Start

import MobxStateMachineRouter, { TStates } from '@mobx-state-machine-router/core';
import URLPersistence from '@mobx-state-machine-router/url-persistence';

// Define states and actions as string literal types
type State = 'home' | 'products' | 'product-detail';
type Action = 'go-products' | 'view-product' | 'go-home';

type Params = {
  productId?: string;
  category?: string;
  search?: string;
};

// Add `url` to each state
const states: TStates<State, Action> = {
  home: {
    actions: { 'go-products': 'products' },
    url: '/',
  },
  products: {
    actions: {
      'go-home': 'home',
      'view-product': 'product-detail',
      'go-products': 'products', // Self-transition for param updates
    },
    url: '/products',
  },
  'product-detail': {
    actions: { 'go-products': 'products' },
    url: '/product',
  },
};

// Create router with URL persistence
const router = MobxStateMachineRouter<State, Params, Action>({
  states,
  currentState: { name: 'home', params: {} },
  persistence: URLPersistence(),
});

// Navigation now updates the URL!
router.emit('go-products');
// URL: /#/products

router.emit('view-product', { productId: '123' });
// URL: /#/product?productId=123

router.emit('go-products', { category: 'electronics', search: 'phone' });
// URL: /#/products?category=electronics&search=phone

API

URLPersistence(options?)

Creates a URL persistence layer.

| Option | Type | Default | Description | |--------|------|---------|-------------| | history | History | createHashHistory() | History instance | | serializers | ISerializers | {} | Custom param serializers |

Custom History

import { createBrowserHistory, createHashHistory, createMemoryHistory } from 'history';

// Hash history (default) - works everywhere, no server config needed
URLPersistence();
URLPersistence({ history: createHashHistory() });

// Browser history - cleaner URLs, requires server config for direct access
URLPersistence({ history: createBrowserHistory() });

// Memory history - useful for testing or SSR
URLPersistence({ history: createMemoryHistory() });

Custom Serializers

Handle complex param types:

URLPersistence({
  serializers: {
    // Boolean
    isActive: {
      getter: (value) => value === 'true',
      setter: (value) => String(value),
    },
    // Array
    tags: {
      getter: (value) => JSON.parse(decodeURIComponent(value)),
      setter: (value) => encodeURIComponent(JSON.stringify(value)),
    },
    // Number
    page: {
      getter: (value) => parseInt(value, 10),
      setter: (value) => String(value),
    },
  },
});

URL Structure

/#/[state-url]?[param1]=[value1]&[param2]=[value2]

| URL | State | Params | |-----|-------|--------| | /#/ | home | {} | | /#/products | products | {} | | /#/products?category=electronics | products | { category: 'electronics' } | | /#/product?productId=123 | product-detail | { productId: '123' } |

Self-Transitions for Query Params

To update query parameters without changing state, add a self-transition:

products: {
  actions: {
    'go-products': 'products', // Self-transition
    // ... other actions
  },
  url: '/products',
},

Then emit with new params:

// Update filters on the same page
router.emit('go-products', { category: 'electronics' });

Usage with React

import { observer } from 'mobx-react-lite';

const ProductsPage = observer(() => {
  const { category, search } = router.currentState.params;

  const handleCategoryChange = (cat: string) => {
    router.emit('go-products', { ...router.currentState.params, category: cat });
  };

  return (
    <div>
      <select value={category} onChange={(e) => handleCategoryChange(e.target.value)}>
        <option value="">All</option>
        <option value="electronics">Electronics</option>
        <option value="clothing">Clothing</option>
      </select>
      {/* URL automatically updates to /#/products?category=electronics */}
    </div>
  );
});

Compatibility

  • MobX 4.x, 5.x, or 6.x
  • history 5.x
  • Works with React, React Native (with memory history), Vue, or vanilla JS

Related

License

MIT © Anzor Bashkhaz