From f10b162d6b5d4ebc3e2807c2538f9fc476e3e6f4 Mon Sep 17 00:00:00 2001 From: Nick Galloway Date: Fri, 11 Sep 2020 22:57:59 -0700 Subject: [PATCH] Add "omitRouter" option (#421) * Add "omitRouter" option --- index.d.ts | 1 + package.json | 2 +- src/ConnectedRouter.js | 11 ++++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 4d5b5770..b42721a6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -18,6 +18,7 @@ declare module 'connected-react-router' { history: History; context?: React.Context; noInitialPop?: boolean; + omitRouter?: boolean; } export type RouterActionType = Action; diff --git a/package.json b/package.json index a8932f70..b74397fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "connected-react-router", - "version": "6.8.0", + "version": "6.8.1", "description": "A Redux binding for React Router v4 and v5", "main": "lib/index.js", "module": "esm/index.js", diff --git a/src/ConnectedRouter.js b/src/ConnectedRouter.js index a2957634..401925bd 100644 --- a/src/ConnectedRouter.js +++ b/src/ConnectedRouter.js @@ -85,7 +85,15 @@ const createConnectedRouter = (structure) => { } render() { - const { history, children } = this.props + const { omitRouter, history, children } = this.props + + // The `omitRouter` option is available for applications that must + // have a Router instance higher in the component tree but still desire + // to use connected-react-router for its Redux integration. + + if (omitRouter) { + return <>{ children } + } return ( @@ -111,6 +119,7 @@ const createConnectedRouter = (structure) => { onLocationChanged: PropTypes.func.isRequired, noInitialPop: PropTypes.bool, stateCompareFunction: PropTypes.func, + omitRouter: PropTypes.bool, } const mapDispatchToProps = dispatch => ({