Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.use((req, res) => {
if (__DEVELOPMENT__) {
// Do not cache webpack stats: the script file would change since
// hot module replacement is enabled in the development env
webpackIsomorphicTools.refresh();
}
const client = new ApiClient(req);
const history = createHistory();
const store = createStore(getRoutes, history, client);
function hydrateOnClient() {
res.send('\n' +
ReactDOM.renderToString());
}
if (__DISABLE_SSR__) {
hydrateOnClient();
return;
}
match({ history, routes: getRoutes(store), location: req.originalUrl }, (error, redirectLocation, renderProps) => {
if (redirectLocation) {
res.redirect(redirectLocation.pathname + redirectLocation.search);
test('History changes when new url is passed to history', t => {
const node = document.createElement('div');
document.body.appendChild(node);
const history = createMemoryHistory();
const onChangeSpy = sinon.spy();
const onLocationChangeSpy = sinon.spy();
render(
,
node
);
history.listen(onLocationChangeSpy);
render(
,
node
);
t.false(onChangeSpy.called);
t.true(onLocationChangeSpy.called);
t.is(onLocationChangeSpy.lastCall.args[0].pathname, '/hello');
});
it('provides the correct routes and query strings for the initial state', () => {
const history = createMemoryHistory();
sandbox.stub(history, 'createLocation').returns({
pathname: '/home/messages/b-team',
search: '?test=ing',
query: {
test: 'ing'
}
});
const initialState = initialRouterState({
history,
routes: {},
pathname: '/home/messages/b-team',
query: {
test: 'ing'
}
});
componentWillReceiveProps() {
componentWillReceivePropsCalled = true;
}
componentDidUpdate() {
componentDidUpdateCalled = true;
}
render() {
return <h3>Content</h3>;
}
}
ReactDOM.render(
,
node,
function() {
this.history.pushState(null, "/page/content2");
}
);
});
}
@exposeMetrics()
class Page extends React.Component {
static willTrackPageView() {
expect(true).to.be.ok;
done();
}
render() {
return <h1>Page</h1>;
}
}
ReactDOM.render(
,
node,
function() {
this.history.pushState(null, "/page/1");
}
);
});
_.merge(props, {
params: _.merge(this.props.params, params),
location: _.merge(this.props.location, { query: query }),
currentUser: fixtures.user,
}),
)
)
},
render() {
return this.renderChildren()
},
})
ReactDOM.render(
,
container,
function() {
cb(TestUtils.findRenderedComponentWithType(this, routeHandler))
},
)
},
JSON.stringify(state)
);
expect(JSON.stringify(routeState.params)).to.equal(
JSON.stringify({id: "123"})
);
done();
return true;
}
render() {
return <div><h2>Page</h2>{this.props.children}</div>;
}
}
ReactDOM.render(
,
node,
function() {
this.history.pushState(state, "/page/123?param1=value1");
}
);
});
});
/**
* Created by mikhail on 16.07.15.
*/
import React from 'react';
import Router from 'react-router';
import Promise from 'promise';
import routes from '../../client/routing/routes.js';
import renderFullPage from '../../utils/renderFullPage.js';
import router from '../../client/routing/router.js';
import createLocation from 'history/lib/createLocation';
import createMemoryHistory from 'history/lib/createMemoryHistory';
const history = createMemoryHistory();
export default function routing(req, res) {
let location = createLocation(req.path);
router(location, history, req, res)
.then((reactEl) => {
try {
let reactStr = React.renderToString(reactEl);
res.send(renderFullPage(reactStr));
} catch (err) {
res.status(500).send({error: err.toString()});
}
}, ({message, code}) => {
console.error(message, code);
res.sendStatus(code || 500);
});
import React from 'react';
import { Router, Route} from 'react-router/umd/ReactRouter';
import createBrowserHistory from 'history/lib/createBrowserHistory';
import createMemoryHistory from 'history/lib/createMemoryHistory';
var history;
if (typeof(window) !== 'undefined'){
history = createBrowserHistory();
}
else {
history = createMemoryHistory(); //This kind of history is needed for server-side rendering.
}
import TodoApp from '../components/TodoApp.react';
import LogDiv from '../components/Logs.react';
import AppContainer from '../components/AppContainer.react';
var routes = (
);
const memoryHistory = useRouterHistory(() => createMemoryHistory(url))(
historyConfig