fix should be getChildRoutes
fix fromNodeCallback returns array of values from callback fix remove require.ensure - needs to be tested
This commit is contained in:
@ -1,3 +1,6 @@
|
||||
import React from 'react';
|
||||
import Router from 'react-router';
|
||||
import Location from 'react-router/lib/Location';
|
||||
import debugFactory from 'debug';
|
||||
import { app$ } from '../../common/app';
|
||||
import { Cat } from 'thundercats';
|
||||
@ -7,7 +10,7 @@ const debug = debugFactory('freecc:servereact');
|
||||
// add routes here as they slowly get reactified
|
||||
// remove their individual controllers
|
||||
const routes = [
|
||||
'/jobs'
|
||||
'/mobile'
|
||||
];
|
||||
|
||||
export default function reactSubRouter(app) {
|
||||
@ -20,13 +23,15 @@ export default function reactSubRouter(app) {
|
||||
app.use(router);
|
||||
|
||||
function serveReactApp(req, res, next) {
|
||||
var fcc = new Cat();
|
||||
var decodedUrl = decodeURI(req.path);
|
||||
const fcc = new Cat();
|
||||
const location = new Location(req.path, req.query)
|
||||
|
||||
// returns a router wrapped app
|
||||
app$(decodedUrl)
|
||||
app$(location)
|
||||
// if react-router does not find a route send down the chain
|
||||
.filter(function(data) {
|
||||
.filter(function(initialState) {
|
||||
console.log('initialState', initialState);
|
||||
/*
|
||||
var state = data.state;
|
||||
// this may not work with react-router 1.0.0
|
||||
var notFound = state.routes.some(route => route.isNotFound);
|
||||
@ -35,19 +40,23 @@ export default function reactSubRouter(app) {
|
||||
next();
|
||||
}
|
||||
return !notFound;
|
||||
*/
|
||||
return true;
|
||||
})
|
||||
.flatMap(function(app) {
|
||||
.flatMap(function(initialState) {
|
||||
// call thundercats renderToString
|
||||
// prefetches data and sets up it up for current state
|
||||
return fcc.renderToString(app);
|
||||
return fcc.renderToString(
|
||||
React.createElement(Router, initialState[0])
|
||||
);
|
||||
})
|
||||
// makes sure we only get one onNext and closes subscription
|
||||
.firstOrDefault()
|
||||
.flatMap(function(dats) {
|
||||
.flatMap(function({ data, markup }) {
|
||||
debug('react rendered');
|
||||
res.expose(dats.data, 'data');
|
||||
res.expose(data, 'data');
|
||||
// now render jade file with markup injected from react
|
||||
return res.render$('layout-react', { markup: dats.markup });
|
||||
return res.render$('layout-react', { markup: markup });
|
||||
})
|
||||
.subscribe(
|
||||
function(markup) {
|
||||
|
Reference in New Issue
Block a user