Update history/react-router
This commit is contained in:
@ -4,7 +4,7 @@ import React from 'react';
|
|||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
import { Router } from 'react-router';
|
import { Router } from 'react-router';
|
||||||
import { routeReducer as routing, syncHistory } from 'react-router-redux';
|
import { routeReducer as routing, syncHistory } from 'react-router-redux';
|
||||||
import { createLocation, createHistory } from 'history';
|
import { createHistory } from 'history';
|
||||||
|
|
||||||
import app$ from '../common/app';
|
import app$ from '../common/app';
|
||||||
import provideStore from '../common/app/provide-store';
|
import provideStore from '../common/app/provide-store';
|
||||||
@ -23,7 +23,7 @@ const serviceOptions = { xhrPath: '/services' };
|
|||||||
|
|
||||||
Rx.config.longStackSupport = !!debug.enabled;
|
Rx.config.longStackSupport = !!debug.enabled;
|
||||||
const history = createHistory();
|
const history = createHistory();
|
||||||
const appLocation = createLocation(
|
const appLocation = history.createLocation(
|
||||||
location.pathname + location.search
|
location.pathname + location.search
|
||||||
);
|
);
|
||||||
const routingMiddleware = syncHistory(history);
|
const routingMiddleware = syncHistory(history);
|
||||||
|
@ -21,7 +21,7 @@ const routes = { components: App, ...childRoutes };
|
|||||||
|
|
||||||
//
|
//
|
||||||
// createApp(settings: {
|
// createApp(settings: {
|
||||||
// location?: Location,
|
// location?: Location|String,
|
||||||
// history?: History,
|
// history?: History,
|
||||||
// initialState?: Object|Void,
|
// initialState?: Object|Void,
|
||||||
// serviceOptions?: Object,
|
// serviceOptions?: Object,
|
||||||
@ -65,13 +65,13 @@ export default function createApp({
|
|||||||
const store = compose(...enhancers)(createStore)(reducer, initialState);
|
const store = compose(...enhancers)(createStore)(reducer, initialState);
|
||||||
|
|
||||||
// createRouteProps({
|
// createRouteProps({
|
||||||
// location: LocationDescriptor,
|
// redirect: LocationDescriptor,
|
||||||
// history: History,
|
// history: History,
|
||||||
// routes: Object
|
// routes: Object
|
||||||
// }) => Observable
|
// }) => Observable
|
||||||
return createRouteProps({ routes, location, history })
|
return createRouteProps({ routes, location, history })
|
||||||
.map(([ nextLocation, props ]) => ({
|
.map(([ redirect, props ]) => ({
|
||||||
nextLocation,
|
redirect,
|
||||||
props,
|
props,
|
||||||
reducer,
|
reducer,
|
||||||
store
|
store
|
||||||
|
@ -76,7 +76,7 @@ export class JobTotal extends PureComponent {
|
|||||||
promoApplied: PropTypes.bool
|
promoApplied: PropTypes.bool
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentWillMount() {
|
||||||
if (!this.props.id) {
|
if (!this.props.id) {
|
||||||
this.props.push('/jobs');
|
this.props.push('/jobs');
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ export class JobPreview extends PureComponent {
|
|||||||
push: PropTypes.func
|
push: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentWillMount() {
|
||||||
const { push, job } = this.props;
|
const { push, job } = this.props;
|
||||||
// redirect user in client
|
// redirect user in client
|
||||||
if (!job || !job.position || !job.description) {
|
if (!job || !job.position || !job.description) {
|
||||||
|
@ -74,7 +74,7 @@
|
|||||||
"gulp-util": "^3.0.6",
|
"gulp-util": "^3.0.6",
|
||||||
"helmet": "^1.1.0",
|
"helmet": "^1.1.0",
|
||||||
"helmet-csp": "^1.0.3",
|
"helmet-csp": "^1.0.3",
|
||||||
"history": "^1.17.0",
|
"history": "^2.0.0",
|
||||||
"jade": "^1.11.0",
|
"jade": "^1.11.0",
|
||||||
"json-loader": "~0.5.2",
|
"json-loader": "~0.5.2",
|
||||||
"less": "^2.5.1",
|
"less": "^2.5.1",
|
||||||
@ -108,8 +108,8 @@
|
|||||||
"react-motion": "~0.4.2",
|
"react-motion": "~0.4.2",
|
||||||
"react-pure-render": "^1.0.2",
|
"react-pure-render": "^1.0.2",
|
||||||
"react-redux": "^4.0.6",
|
"react-redux": "^4.0.6",
|
||||||
"react-router": "^1.0.0",
|
"react-router": "^2.0.0",
|
||||||
"react-router-bootstrap": "https://github.com/FreeCodeCamp/react-router-bootstrap.git#freecodecamp",
|
"react-router-bootstrap": "~0.20.1",
|
||||||
"react-toastr": "^2.4.0",
|
"react-toastr": "^2.4.0",
|
||||||
"react-router-redux": "^2.1.0",
|
"react-router-redux": "^2.1.0",
|
||||||
"react-vimeo": "~0.1.0",
|
"react-vimeo": "~0.1.0",
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { RoutingContext } from 'react-router';
|
import { RouterContext } from 'react-router';
|
||||||
import { createLocation } from 'history';
|
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
|
|
||||||
import renderToString from '../../common/app/utils/render-to-string';
|
import renderToString from '../../common/app/utils/render-to-string';
|
||||||
@ -39,15 +38,15 @@ export default function reactSubRouter(app) {
|
|||||||
|
|
||||||
function serveReactApp(req, res, next) {
|
function serveReactApp(req, res, next) {
|
||||||
const serviceOptions = { req };
|
const serviceOptions = { req };
|
||||||
const location = createLocation(req.path);
|
|
||||||
|
|
||||||
// returns a router wrapped app
|
|
||||||
app$({
|
app$({
|
||||||
location,
|
location: req.path,
|
||||||
serviceOptions
|
serviceOptions
|
||||||
})
|
})
|
||||||
// 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(({ props }) => {
|
.filter(({ redirect, props }) => {
|
||||||
|
if (!props && redirect) {
|
||||||
|
res.redirect(redirect.pathname + redirect.search);
|
||||||
|
}
|
||||||
if (!props) {
|
if (!props) {
|
||||||
log(`react tried to find ${location.pathname} but got 404`);
|
log(`react tried to find ${location.pathname} but got 404`);
|
||||||
return next();
|
return next();
|
||||||
@ -58,7 +57,7 @@ export default function reactSubRouter(app) {
|
|||||||
log('render react markup and pre-fetch data');
|
log('render react markup and pre-fetch data');
|
||||||
|
|
||||||
return renderToString(
|
return renderToString(
|
||||||
provideStore(React.createElement(RoutingContext, props), store)
|
provideStore(React.createElement(RouterContext, props), store)
|
||||||
)
|
)
|
||||||
.map(({ markup }) => ({ markup, store }));
|
.map(({ markup }) => ({ markup, store }));
|
||||||
})
|
})
|
||||||
|
@ -28,7 +28,6 @@ export default function getJobServices(app) {
|
|||||||
},
|
},
|
||||||
read(req, resource, params, config, cb) {
|
read(req, resource, params, config, cb) {
|
||||||
const id = params ? params.id : null;
|
const id = params ? params.id : null;
|
||||||
console.log('params', params);
|
|
||||||
if (id) {
|
if (id) {
|
||||||
return Job.findById(id)
|
return Job.findById(id)
|
||||||
.then(job => cb(null, job.toJSON()))
|
.then(job => cb(null, job.toJSON()))
|
||||||
|
Reference in New Issue
Block a user