Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const removeHistoryListener = history.listen(location => {
currentLocation = location
match(routes, {
path: location.pathname,
query: location.query,
state: location.state,
context,
render: render.bind(undefined, container, location.state, {store})
}).catch(err => console.error(err)) // eslint-disable-line no-console
})
store.dispatch(setRuntimeVariable({
name: 'initialNow',
value: Date.now()
}))
store.dispatch(setRuntimeVariable({
name: 'availableLocales',
value: locales
}))
await store.dispatch(setLocale({
locale
}))
await match(routes, {
path: req.path,
query: req.query,
context: {
store,
insertCss: (...styles) => { styles.forEach(style => css.push(style._getCss())) }, // eslint-disable-line no-underscore-dangle
setTitle: value => (data.title = value),
setMeta: (key, value) => (data[key] = value)
},
render (component, status = 200) {
css = []
statusCode = status
// Fire all componentWill... hooks
data.body = ReactDOM.renderToString({ component })
// If you have async actions, wait for store when stabilizes here.
export default (routes, context, location) => {
return match(routes(context), location).then(renderProps => {
//context.router = history
if (process.env.BROWSER && firstRender) {
firstRender = false
return renderProps.component
}
return fetchData(renderProps, context).then(() => renderProps.component)
})
}