Creator of Souin
Træfik helper
SkillValue speaker
Developer
@Darkweak
@Darkweak_dev
Developed by Facebook
Started on late 2011
Opensourced on mid 2013
Jordan Walke et Pete Hunt
Javascript library
Virtual DOM
Easy switch to RN
Powerful
Javascript only
app.get('*', async (req: any, res: any) => {
let state = {};
const actions: any[] = [];
matchRoutes(
routes.map(r => ({
...r,
exact: true,
path: `/:language([a-z]{2})${r.path}`
})),
req.path
)
.map(
({ route }: any) =>
route.component?.getInitialProps ?
route.component.getInitialProps(req.path.split('/')) :
[]
)
.map(action => actions.push(...action));
await Promise
.all(actions)
.then((result: any) => result.forEach(
(r: any) => state = {...state, ...r}
)).catch(console.log);
const content = render({}, req.path, state);
res.send(content);
});
Item.getInitialProps = ([,,, slug]: [string, string, string, string]) => {
return [
new Conference()
.get({ id: slug })
.then(conference => ({
conference: {
[`${ conference.city }-${ conference.date }`]: conference
}
}))
];
};
<script>window.INITIAL_STATE = ${ JSON.stringify(state) }</script>
renderToString(
<BaseStoreProvider>
<StaticRouter location={path} context={context}>
<Switch>
{
routes.map(
(route: IRoute, index: number) => {
const Tag: any = route.component;
return (
<Route
key={index}
exact
path={'/' === route.path ? '' : route.path}
render={() => <LanguageProvider><Tag/></LanguageProvider>}
/>
)
})}
</Switch>
</StaticRouter>
</BaseStoreProvider>
);
import { ChunkExtractor } from '@loadable/server';