explaingit

supasate/connected-react-router

4,695JavaScriptAudience · developerComplexity · 3/5Setup · moderate

TLDR

A JavaScript library that syncs Redux and React Router so the current URL is always part of your app's data store, letting you trigger navigation via Redux actions and replay navigation history with time-travel debugging.

Mindmap

mindmap
  root((connected-react-router))
    What it does
      Syncs URL to Redux store
      Navigation via actions
      Time travel debugging
    Setup Steps
      Add router reducer
      Apply middleware
      Wrap with ConnectedRouter
    Use Cases
      Redirect after form submit
      Read URL in any component
      Replay navigation history
    Tech Stack
      JavaScript
      React and Redux
      React Router
      TypeScript
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Trigger a page redirect after a successful form submission by dispatching a standard Redux action.

USE CASE 2

Read the current URL in any Redux-connected component without wiring it into the router separately.

USE CASE 3

Use Redux DevTools to step backwards and forwards through navigation history alongside state changes.

USE CASE 4

Build a React app where all navigation is controlled by and recorded in the Redux store.

Tech stack

JavaScriptReactReduxReact RouterTypeScriptImmutable.js

Getting it running

Difficulty · moderate Time to first run · 30min

All three setup pieces, router reducer, middleware, and ConnectedRouter, must share the same history object, which requires careful wiring.

In plain English

Connected React Router is a JavaScript library for web developers building apps with React. It solves a specific coordination problem: when you use Redux to manage your app's data and React Router to handle page navigation, the two systems normally operate independently and can fall out of sync. This library links them together so that the current URL is always reflected in the Redux data store, and changes to that store can trigger navigation. The practical benefit is that navigation becomes part of the same data flow as everything else in the app. You can trigger a page change by dispatching a standard Redux action, which is useful when navigation needs to happen as a side effect of some other action, like successfully submitting a form. Any component that is connected to the Redux store can also read the current URL directly, without needing to be wired into the router separately. Another benefit is time-travel debugging. Redux DevTools lets you step backwards and forwards through the history of state changes in your app. With this library, those steps also move the browser URL backwards and forwards to match, so you can replay sequences of events including the pages a user visited. Setting up the library requires three steps: adding a router section to your Redux reducer, applying a piece of middleware when creating the store, and wrapping your routing components with a ConnectedRouter wrapper. All three steps need to share the same history object, which tracks the browser's navigation state. The library supports TypeScript and works with Immutable.js for teams that use those tools. It covers React Router versions 4 and 5. The README includes code examples for each setup step and a FAQ covering common scenarios like server-side rendering and React Native.

Copy-paste prompts

Prompt 1
Show me how to set up connected-react-router so I can navigate to /dashboard by dispatching a Redux action after a successful login.
Prompt 2
Write the Redux store setup for connected-react-router including the router reducer, middleware, and ConnectedRouter wrapper with a shared history object.
Prompt 3
Using connected-react-router, how do I redirect to a new page as a side effect inside a Redux Thunk action creator?
Prompt 4
Set up connected-react-router with TypeScript and show me how to type the router state in my Redux store.
Prompt 5
How do I use Redux DevTools with connected-react-router to replay the sequence of pages a user visited?
Open on GitHub → Explain another repo

← supasate on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.