react-state-rxjs
  • Introduction
  • Main differences
  • Performance first
  • GETTING STARTED
    • Instalation
    • Examples
  • Core concepts
    • Main idea
      • More complex flow visualization
    • Configuration
    • Store
      • Operators
      • Optimistic updates plugin
      • Form manager plugin
        • ShouldUpdateState hook
        • Custom form elements
      • Persist state plugin
        • Configuring custom storage
    • Actions
      • Immer
      • ImutableJs
      • Async
    • Components with Actions
    • @InjectStore decorator
    • @ComponentState decorator
    • ComponentState Hook
    • Dispatcher
    • Router / History
  • DIFFERENT SCENARIOS
    • Passing list item index via router
  • UNIT TESTING
    • Setup
    • Test store
    • Test actions
    • Test component with actions
    • Test with Enzyme
  • Debugging
    • Setup
    • Redux DevTools
    • Automated changes output
    • Manual state changes check
    • Additional debugging information
  • Production
    • Production mode
  • Other information
    • Best practices
    • CLI
      • Custom Configurations
    • Performance
    • Blog Posts
    • Contributing
Powered by GitBook
On this page

Was this helpful?

  1. Core concepts

Router / History

@react-sate/store uses two kind of router history

  • createMemoryHistory

  • createBrowserHistory

createMemoryHistory - is used when SSR is enabled and when running unit tests wth ReactStateTestBed

createBrowserHistory - is used in browser app

In order to do redirects you need to do history.push and pass route you want to navigate to. Usually, in React, history is passed via props. However there are cases where you would like to do navigation from place where props are not accessible - like from service e.g. you would like to redirect user to login page from auth service or from http service if response is 401.

For this reason @react-state/store exposes history object. It can be accessed via RouterHistory class.

import { RouterHistory } from '@react-state/store';
...
RouterHistory.history.push('/login');
PreviousDispatcherNextPassing list item index via router

Last updated 5 years ago

Was this helpful?