UNPKG

redux-first-router

Version:

think of your app in states not routes (and, yes, while keeping the address bar in sync)

28 lines (21 loc) 996 B
import { updateScroll } from '../connectRoutes'; export default (function (dispatch, getState, route, selectLocationState, bag) { if (typeof window !== 'undefined') { var thunk = route.thunk; if (typeof thunk === 'function') { var _selectLocationState = selectLocationState(getState()), kind = _selectLocationState.kind, hasSSR = _selectLocationState.hasSSR; // call thunks always if it's not initial load of the app or only if it's load // without SSR setup yet, so app state is setup on client when prototyping, // such as with with webpack-dev-server before server infrastructure is built. // NEW: if there is no path, it's assumed to be a pathless route, which is always called. if (kind !== 'load' || kind === 'load' && !hasSSR || !route.path) { var prom = thunk(dispatch, getState, bag); if (prom && typeof prom.next === 'function') { prom.next(updateScroll); } } } } });