Разобрался, но это была БОЛЬ!
Это было условие гонки, потому что новые маршруты не были сгенерированы достаточно быстро, когда routeInterceptor изменил маршруты.
А в другом модуле routeManager нам нужно было добавить location
в соединение только к watch
it.
routeManager
import React from 'react';
import { connect } from 'react-redux';
// React router
import { Route, Switch } from 'react-router-dom';
import { ConnectedRouter } from 'react-router-redux';
// Actions
import { onAuthStateChange } from 'actions/Auth';
// MUI Components
import CssBaseline from '@material-ui/core/CssBaseline';
// Components
import Main from 'components/Common/main';
import Loading from 'components/Common/loading';
import * as components from 'components';
// Utils
import history from 'clientHistory';
import { cleanMapStateToProps } from 'utils/redux';
import { getRoutesArray } from 'utils/routes';
// Copy
import { PAGE_AUTH_REQS } from 'copy/Global/routes';
const {
AUTHORIZED,
UNAUTHORIZED
} = PAGE_AUTH_REQS;
const getComponentForRoute = compName => (
components[compName] || (() => null)
);
const getRouteComponents = FILTER => getRoutesArray(FILTER)
.map(route => ({
...route,
component: getComponentForRoute(route.component)
}))
.map(route => (<Route {...route} key={route.label} />));
class RouteManager extends React.Component {
componentDidMount() {
this.props.onAuthStateChange();
}
renderAuthorizedRoutes() {
const routes = getRouteComponents(AUTHORIZED);
return (
<ConnectedRouter history={history}>
<Main
signOut={this.signOut}
notifications={this.props.notifications}
currentNotification={this.props.currentNotification}
>
<CssBaseline />
<Switch>
{routes}
</Switch>
</Main>
</ConnectedRouter>
);
}
renderUnauthorizedRoutes() {
const routes = getRouteComponents(UNAUTHORIZED);
return (
<ConnectedRouter history={history}>
<Main
signOut={this.signOut}
notifications={this.props.notifications}
currentNotification={this.props.currentNotification}
>
<CssBaseline />
<Switch>
{routes}
</Switch>
</Main>
</ConnectedRouter>
);
}
render() {
const { authed } = this.props;
if (authed === null) {
return <Loading />;
}
return authed
? this.renderAuthorizedRoutes()
: this.renderUnauthorizedRoutes();
}
}
export const RouteManagerJest = RouteManager;
const mapDispatchToProps = dispatch => ({
onAuthStateChange: () => { dispatch(onAuthStateChange()); }
});
export default connect(cleanMapStateToProps([
'authed',
'location', // <-- Needed to just add location here.
'currentNotification',
'notifications'
]), mapDispatchToProps)(RouteManager);
export default connect(cleanMapStateToProps([
'authed',
'location', // <-- Needed to just add location here.
'currentNotification',
'notifications'
]), mapDispatchToProps)(RouteManager);
ways.js
import { PAGE_AUTH_REQS } from 'copy/Global/routes';
export const PROP_CONTENT_ROUTE = '[[ContentRoute]]';
const exact = true;
const {
ANY,
AUTHORIZED,
UNAUTHORIZED
} = PAGE_AUTH_REQS;
/**
* Do not export routes - if you need to get a list of routes (as an array or
* object), use one of the convenience methods down below.
*/
const routesConfig = {
// Auth Routes => /:context
authLogin: {
label: 'Login',
path: '/login',
title: 'Login',
authReq: UNAUTHORIZED,
component: 'Login',
exact
},
authResetPassword: {
label: 'Reset',
path: '/reset-password',
title: 'Reset Password',
authReq: UNAUTHORIZED,
component: 'ResetPassword',
exact
},
authRedirector: {
label: 'Redirect',
path: '/redirect',
title: 'Firebase Redirect',
authReq: UNAUTHORIZED,
component: 'FirebaseRedirector',
exact
},
authChangePassword: {
label: 'Change',
path: '/change-password/:oobCode/',
title: 'Change Password',
authReq: UNAUTHORIZED,
component: 'ChangePassword',
exact
},
authVerification: {
label: 'Verify',
path: '/verification',
title: 'Verify your email',
authReq: UNAUTHORIZED,
component: 'Login',
exact
},
authRestricted: {
label: 'Restricted Access',
path: '/restricted-access',
title: 'Restricted Access',
authReq: UNAUTHORIZED,
component: 'RestrictedAccess',
exact
},
products: {
label: 'Products',
path: '/(products)?',
title: 'Products',
authReq: AUTHORIZED,
component: 'Products'
},
// ********************************************************
// ********************************************************
// ********************************************************
// ANY ROUTES BELOW RouteInterceptor WILL NOT BE CONSIDERED
// ********************************************************
// ********************************************************
// ********************************************************
routeInterceptor: {
label: null,
title: null,
authReq: ANY,
component: 'RouteInterceptor'
}
};
export default routesConfig;
И теперь, наконец, все работает как положено.