diff --git a/src/components/App.js b/src/components/App.js index 316d82b..f3aef34 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -1,6 +1,6 @@ import React from 'react'; import { Route, Switch } from 'react-router-dom'; -import { Home, NotFoundWrapper } from '.'; +import { NotFoundWrapper } from '.'; import { MainContainer, PostContainer } from '../containers'; export const App = () => ( diff --git a/src/utils/routes.js b/src/utils/routes.js new file mode 100644 index 0000000..5770a7a --- /dev/null +++ b/src/utils/routes.js @@ -0,0 +1,26 @@ +import { MainContainer, PostContainer } from '../containers' +import { NotFoundWrapper } from '../components'; +import getData from './api' + +const routes = [ + { + path: '/', + exact: true, + component: MainContainer, + getData: (path = '') => getData( + path.split('/').pop() + ) + }, + { + path: '/post/:postname', + component: PostContainer, + getData: (path = '') => getData( + path.split('/').pop() + ) + }, + { + component: NotFoundWrapper, + } +] + +export default routes diff --git a/src/utils/serverRender.js b/src/utils/serverRender.js index 523b62b..1b54d94 100644 --- a/src/utils/serverRender.js +++ b/src/utils/serverRender.js @@ -4,8 +4,13 @@ import { renderToString } from 'react-dom/server' import { StaticRouter as Router } from 'react-router-dom' import { App } from '../components/App' import manifest from '../../public/static/manifest.json' +import routes from './routes' function serverRender(req, res) { + + const activeRoute = routes.find((route) => matchPath(req.url, route)) || {} + + let markup = ''; let status = 200;