Refactor routes
This commit is contained in:
parent
93d2822600
commit
7670ade223
|
@ -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 = () => (
|
||||
|
|
|
@ -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
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue