Skip to content

Commit c543e2e

Browse files
committed
fix(docs): routing recipe for react-router v4 updated - prescottprue#325
1 parent d1d9044 commit c543e2e

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

docs/recipes/routing.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ Routing can be changed based on data by using react lifecycle hooks such as `com
1010
import React, { Component } from 'react'
1111
import PropTypes from 'prop-types'
1212
import { connect } from 'react-redux'
13-
import { firebaseConnect, isLoaded, isEmpty } from 'react-redux-firebase'
13+
import { isLoaded, isEmpty } from 'react-redux-firebase'
1414

1515
const enhance = compose(
16-
firebaseConnect(),
1716
connect(
1817
({ firebase: { auth } }) => ({
1918
auth, // state.firebase.auth -> props.auth
@@ -79,7 +78,7 @@ export const UserIsAuthenticated = UserAuthWrapper({
7978

8079
```javascript
8180
import locationHelperBuilder from 'redux-auth-wrapper/history4/locationHelper';
82-
import { browserHistory } from 'react-router';
81+
import { connectedRouterRedirect } from 'redux-auth-wrapper'
8382
import LoadingScreen from '../components/LoadingScreen'; // change it to your custom component
8483

8584
const locationHelper = locationHelperBuilder({});
@@ -180,21 +179,26 @@ export const UserIsNotAuthenticated = UserAuthWrapper({
180179
**react-router v4 + redux-auth-wrapper v2**
181180

182181
```js
183-
import { browserHistory } from 'react-router'
184-
import { UserAuthWrapper } from 'redux-auth-wrapper'
182+
import locationHelperBuilder from 'redux-auth-wrapper/history4/locationHelper';
183+
import { connectedRouterRedirect } from 'redux-auth-wrapper'
184+
185185
import LoadingScreen from '../components/LoadingScreen'; // change it to your custom component
186186

187-
export const UserIsNotAuthenticated = UserAuthWrapper({
187+
export const UserIsNotAuthenticated = connectedRouterRedirect({
188188
wrapperDisplayName: 'UserIsNotAuthenticated',
189-
allowRedirectBack: false,
190189
AuthenticatingComponent: LoadingScreen,
190+
allowRedirectBack: false,
191191
redirectPath: (state, ownProps) =>
192192
locationHelper.getRedirectQueryParam(ownProps) || '/',
193-
authenticatedSelector: ({ firebase }) => pathToJS(firebase, 'auth') === null,
194-
authenticatingSelector: ({ firebase }) =>
195-
pathToJS(firebase, 'isInitializing') === true ||
196-
pathToJS(firebase, 'auth') === undefined
197-
})
193+
authenticatingSelector: ({ firebase: { auth, isInitializing } }) =>
194+
!auth.isLoaded || isInitializing === true,
195+
authenticatedSelector: ({ firebase: { auth } }) =>
196+
auth.isLoaded && auth.isEmpty,
197+
redirectAction: newLoc => (dispatch) => {
198+
// routerActions.replace or other redirect
199+
dispatch({ type: 'UNAUTHED_REDIRECT' });
200+
},
201+
});
198202
```
199203

200204
Can then be used on a Login route component:

0 commit comments

Comments
 (0)