For reference, I am using the React-Redux Starter Kit (https://github.com/davezuko/react-redux-starter-kit) as a base project layout.
Ive got a route named TSP
, and I am using getComponent
and redux connect()
to inject a reducer on a container component, which i am hoping will pass children
on in the props.
The getChildRoutes
in the TSP route definition is never being called.
Root Router Config:
import ApplicationLayout from '../layouts/ApplicationLayout';
import Home from './Home';
export const createRoutes = (store) => {
const routes = {
path: '/',
component: ApplicationLayout,
indexRoute: Home,
getChildRoutes (location, next) {
require.ensure([], (require) => {
next(null, [
require('./TSP').default(store),
require('./Home').default,
]);
});
}
};
return routes;
};
export default createRoutes;
Nested Router Config (TSP):
import { injectReducer } from '../../store/reducers';
import Overview from './routes/Overview';
export default (store) => ({
path: '/tsp/:id',
indexRoute: Overview,
getComponent (nextState, next) {
require.ensure([
'./containers/TSPContainer',
'./modules/tsp'
], (require) => {
const TSP = require('./containers/TSPContainer').default;
const reducer = require('./modules/tsp').default;
injectReducer(store, { key: 'tsp', reducer });
next(null, TSP);
});
},
getChildRoutes (location, next) {
debugger
require.ensure([], (require) => {
next(null, [
// Provide store for async reducers and middleware
require('./routes/Offers').default(store),
require('./routes/Reviews').default(store)
]);
});
}
});
I am never getting to the debugger
within getChildRoutes
.
Any help is appreciated, and if there are any more files necessary to see I can add them.
Have you synchronously loaded the
./TSP
and./Home
route definitions? If not, I don't thinkrequire.ensure
would work without you specifying those modules as dependencies.So:
Figured it out. My
IndexRoute
in the aboveTSP
nested router config was a function, not an object (which i'm assuming react-router was expecting indexRoute to be an object before firinggetChildRoutes
.)The solution was to assign the resolved the routeConfig for
Overview
toindexRoute
.TSP/index.js
TSP/routes/Overview/index.js