|
1 | 1 | /**
|
2 | 2 | * Created by ink on 2018/5/3.
|
3 | 3 | */
|
4 |
| - |
5 |
| -import React from 'react' |
6 |
| -import {renderToString} from 'react-dom/server' |
7 |
| -import Component from '../../client/pages/example/App' |
8 | 4 | import extractMapping from '../middleware/extractMapping'
|
9 |
| -import mapAssets from '../utils/mapAssets' |
10 |
| -import {StaticRouter} from 'react-router' |
11 |
| - |
12 |
| -import {Provider} from 'react-redux' |
13 |
| -import store from '../../client/pages/tools/store/forServer' |
14 |
| -import {Content} from '../../client/pages/integration/Root/index' |
15 |
| -import Integration from '../../client/pages/integration/App' |
16 |
| -import reducers from '../../client/pages/integration/store/' |
17 | 5 | import express from 'express'
|
| 6 | + |
| 7 | +import integrationController from '../controller/integration' |
| 8 | +import componentsController from '../controller/components' |
18 | 9 | const router = express.Router()
|
19 | 10 |
|
20 | 11 | router.get('/', (req, res) => {
|
21 | 12 | res.status(301).set('Location', '/').end()
|
22 | 13 | })
|
23 | 14 |
|
24 |
| -router.get('/integration(/:page)?', extractMapping, (req, res, next) => { |
25 |
| - const location = `${req.baseUrl}${req.path}` |
26 |
| - const content = renderToString(<Provider store={store(reducers)}> |
27 |
| - <StaticRouter |
28 |
| - location={location} |
29 |
| - context={{}} |
30 |
| - basename="/p/integration" |
31 |
| - > |
32 |
| - <Content component={Integration}/> |
33 |
| - </StaticRouter> |
34 |
| - </Provider>) |
35 |
| - res.render('integration', { |
36 |
| - app: content, |
37 |
| - links: mapAssets('integration/index.css'), |
38 |
| - scripts: mapAssets('integration/index.js') |
39 |
| - }) |
40 |
| -}) |
| 15 | +router.use('/integration', extractMapping, integrationController.router) |
| 16 | + |
| 17 | +router.use('/components', extractMapping, componentsController.router) |
41 | 18 |
|
42 |
| -router.get('/components(/:page)?', extractMapping, (req, res, next) => { |
43 |
| - //可以根据路径,针对某一个页面进行服务端渲染 |
44 |
| - const location = `${req.baseUrl}${req.path}` |
45 |
| - const content = renderToString(<StaticRouter |
46 |
| - location={location} |
47 |
| - context={{}} |
48 |
| - basename="/p/components"> |
49 |
| - <Component/> |
50 |
| - </StaticRouter>) |
51 |
| - res.render('components', { |
52 |
| - app: content, |
53 |
| - links: mapAssets('components/index.css'), |
54 |
| - scripts: mapAssets('components/index.js') |
55 |
| - }) |
56 |
| -}) |
57 | 19 | export default router
|
0 commit comments