fix not found calls next

This commit is contained in:
Berkeley Martinez
2015-07-03 21:46:22 -07:00
parent 4c8a8a4875
commit ef7e0c67ee
4 changed files with 14 additions and 21 deletions

View File

@@ -9,7 +9,7 @@ export default React.createClass({
render() { render() {
const { const {
id id
} = this.props; } = this.props.params;
return ( return (
<h2>Hello { id }</h2> <h2>Hello { id }</h2>

View File

@@ -1,7 +1,7 @@
import Hikes from './components/Hikes.jsx'; import Hikes from './components/Hikes.jsx';
export default { export default {
path: 'hikes', path: 'hikes(/:id)',
getComponents(cb) { getComponents(cb) {
setTimeout(() => { setTimeout(() => {

View File

@@ -1,4 +1,4 @@
import Jobs from './Jobs'; // import Jobs from './Jobs';
import Hikes from './Hikes'; import Hikes from './Hikes';
export default { export default {
@@ -6,8 +6,7 @@ export default {
getChildRoutes(locationState, cb) { getChildRoutes(locationState, cb) {
setTimeout(() => { setTimeout(() => {
cb(null, [ cb(null, [
// require('./Bonfires'), // Jobs,
Jobs,
Hikes Hikes
]); ]);
}, 0); }, 0);

View File

@@ -10,7 +10,9 @@ const debug = debugFactory('freecc:servereact');
// add routes here as they slowly get reactified // add routes here as they slowly get reactified
// remove their individual controllers // remove their individual controllers
const routes = [ const routes = [
'/Hikes' '/Hikes',
'/Hikes/:id',
'/jobs'
]; ];
export default function reactSubRouter(app) { export default function reactSubRouter(app) {
@@ -29,29 +31,21 @@ export default function reactSubRouter(app) {
// returns a router wrapped app // returns a router wrapped app
app$(location) app$(location)
// if react-router does not find a route send down the chain // if react-router does not find a route send down the chain
.filter(function(initialState) { .filter(function([ initialState ]) {
console.log('initialState', initialState); if (!initialState) {
/* debug('tried to find %s but got 404', location.pathname);
var state = data.state; return next();
// this may not work with react-router 1.0.0
var notFound = state.routes.some(route => route.isNotFound);
if (notFound) {
debug('tried to find %s but got 404', state.path);
next();
} }
return !notFound; return !!initialState;
*/
return true;
}) })
.flatMap(function(initialState) { .flatMap(function([ initialState ]) {
// call thundercats renderToString // call thundercats renderToString
// prefetches data and sets up it up for current state // prefetches data and sets up it up for current state
return fcc.renderToString( return fcc.renderToString(
React.createElement(Router, initialState[0]) React.createElement(Router, initialState)
); );
}) })
// makes sure we only get one onNext and closes subscription // makes sure we only get one onNext and closes subscription
.firstOrDefault()
.flatMap(function({ data, markup }) { .flatMap(function({ data, markup }) {
debug('react rendered'); debug('react rendered');
res.expose(data, 'data'); res.expose(data, 'data');