diff --git a/js/app.js b/js/app.js
index e2c7e1e6..586ec481 100644
--- a/js/app.js
+++ b/js/app.js
@@ -10,11 +10,14 @@ import Router from 'react-router/es6/Router';
import AppResolver from './app_resolver';
import history from './history';
+import AppConstants from './constants/application_constants';
+
import { getDefaultSubdomainSettings, getSubdomainSettings } from './utils/constants_utils';
import { initLogging } from './utils/error_utils';
import { getSubdomain } from './utils/general_utils';
import requests from './utils/requests';
+
// FIXME: rename these event actions
import EventActions from './actions/event_actions';
@@ -51,7 +54,19 @@ const AppGateway = {
// `history.listen` is called on every route change, which is perfect for routeDidChange
// events.
- history.listen(EventActions.routeDidChange);
+ // For history <= 3.0, history.listen will synchronously invoke the callback once
+ // immediately after registration.
+ history.listen((location) => {
+ const { locationQueue } = history;
+ locationQueue.unshift(location);
+
+ // Limit the number of locations to keep in memory to avoid too much memory usage
+ if (locationQueue.length > AppConstants.locationThreshold) {
+ locationQueue.length = AppConstants.locationThreshold;
+ }
+
+ EventActions.routeDidChange(location);
+ });
// Adds a client specific class to the body for whitelabel styling
window.document.body.classList.add(`client--${settings.subdomain}`);
diff --git a/js/components/app_base.js b/js/components/app_base.js
index d6528d28..34a48f55 100644
--- a/js/components/app_base.js
+++ b/js/components/app_base.js
@@ -1,7 +1,6 @@
'use strict';
import React from 'react';
-import classNames from 'classnames';
import UserActions from '../actions/user_actions';
import UserStore from '../stores/user_store';
@@ -11,8 +10,6 @@ import WhitelabelStore from '../stores/whitelabel_store';
import GlobalNotification from './global_notification';
-import AppConstants from '../constants/application_constants';
-
import { mergeOptions } from '../utils/general_utils';
@@ -22,8 +19,6 @@ export default function AppBase(App) {
propTypes: {
children: React.PropTypes.element.isRequired,
- //FIXME: test if this is actually passed down now
- history: React.PropTypes.object.isRequired,
location: React.PropTypes.object.isRequired,
routes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired
},
@@ -41,18 +36,6 @@ export default function AppBase(App) {
UserActions.fetchCurrentUser();
WhitelabelActions.fetchWhitelabel();
-
- this.history.locationQueue.push(this.props.location);
- },
-
- componentWillReceiveProps(nextProps) {
- const { locationQueue } = this.history;
- locationQueue.unshift(nextProps.location);
-
- // Limit the number of locations to keep in memory to avoid too much memory usage
- if (locationQueue.length > AppConstants.locationThreshold) {
- locationQueue.length = AppConstants.locationThreshold;
- }
},
componentWillUnmount() {
@@ -85,4 +68,4 @@ export default function AppBase(App) {
);
}
});
-};
+}
diff --git a/js/components/ascribe_routes/proxy_handler.js b/js/components/ascribe_routes/proxy_handler.js
index 70bb53ee..92e0e6da 100644
--- a/js/components/ascribe_routes/proxy_handler.js
+++ b/js/components/ascribe_routes/proxy_handler.js
@@ -1,7 +1,6 @@
'use strict';
import React from 'react';
-import history from '../../history';
import UserStore from '../../stores/user_store';
@@ -24,7 +23,7 @@ export function AuthRedirect({ to, when }) {
throw new Error(`"when" must be one of: [${whenValues}] got "${when}" instead`);
}
- return function(currentUser, query) {
+ return function redirectRoute(router, currentUser, query) {
const { redirectAuthenticated, redirect } = query;
// The user of this handler specifies with `when`, what kind of status
@@ -38,14 +37,14 @@ export function AuthRedirect({ to, when }) {
// and redirect if `true`.
if (exprToValidate) {
- window.setTimeout(() => history.replace({ query, pathname: to }));
+ window.setTimeout(() => router.replace({ query, pathname: to }));
return true;
// Otherwise there can also be the case that the backend
// wants to redirect the user to a specific route when the user is logged out already
} else if (!exprToValidate && when === 'loggedIn' && redirect) {
delete query.redirect;
- window.setTimeout(() => history.replace({ query, pathname: `/${redirect}` }));
+ window.setTimeout(() => router.replace({ query, pathname: `/${redirect}` }));
return true;
} else if (!exprToValidate && when === 'loggedOut' && redirectAuthenticated) {
@@ -75,8 +74,8 @@ export function AuthRedirect({ to, when }) {
* @param {[function]} redirectFn A function that conditionally redirects
*/
export function ProxyHandler(...redirectFunctions) {
- return (Component) => {
- return React.createClass({
+ return (Component) => (
+ React.createClass({
displayName: 'ProxyHandler',
propTypes: {
@@ -94,8 +93,7 @@ export function ProxyHandler(...redirectFunctions) {
},
childContextTypes: {
- route: object,
- router: object
+ route: object
},
getChildContext() {
@@ -121,7 +119,7 @@ export function ProxyHandler(...redirectFunctions) {
// it should return `true` and therefore
// stop/avoid the execution of all functions
// that follow
- if (redirectFunctions[i](currentUser, query)) {
+ if (redirectFunctions[i](this.context.router, currentUser, query)) {
break;
}
}
@@ -133,6 +131,6 @@ export function ProxyHandler(...redirectFunctions) {