MobX State Router

MobX State Router

  • Docs
  • GitHub

›API

Guides

  • Getting Started
  • Recipes
  • Examples

API

  • Route
  • RouterLink
  • RouterState
  • RouterStore
  • RouterView
  • HistoryAdapter
  • StaticAdapter

RouterState

RouterState holds the state of the router. It is a simple object conforming to the following interface. RouterState can be serialized and deserialized. This is useful for server-side rendering.

interface RouterState {
    // Example 'department'
    routeName: string;

    // Example { id: 'electronics' }
    params: StringMap;

    // Example { q: 'apple' } or { items: ['E1', 'E2'] }
    queryParams: { [key: string]: any };

    options: { [key: string]: any };
}

Never construct a RouterState from scratch, instead use the createRouterState() factory method. Treat RouterState as immutable. If you need a new RouterState, create a fresh one.

createRouterState()

Syntax

const createRouterState = (
    routeName: string,
    options: { [key: string]: any } = {}
) => RouterState;

Parameters

routeName

Example 'department'

options

Array of key-value pairs to store into RouterState. The following options are supported. However, you can pass additional options that you may want to use in transition hooks.

params: StringMap
    Example { id: 'electronics' }
queryParams: { [key: string]: any }
    Example { q: 'apple' } or { items: ['E1', 'E2'] }
replaceHistory: boolean
    If true, the router uses history.replace() when transitioning to a new state.
    The default is to use history.push().

Return value

An instance of RouterState.

← RouterLinkRouterStore →
  • createRouterState()
    • Syntax
    • Parameters
    • Return value
Copyright © 2021 Naresh Bhatia