entry-server.js
1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import {createApp} from './app';
import createReport from 'report-error';
import {
SET_SERVER_INFO,
ROUTE_CHANGE
} from 'store/yoho/types';
export default context => {
const reportError = createReport(context);
return new Promise((resolve, reject) => {
const {app, router, store} = createApp(context);
const {url} = context;
store.commit(SET_SERVER_INFO, {context});
router.push(url);
router.onReady(() => {
const matched = router.getMatchedComponents();
store.commit(ROUTE_CHANGE, {to: router.currentRoute});
if (matched.some(m => !m)) {
reportError(new Error('导航组件为空'));
return reject({code: 500, message: ''});
}
if (!matched.length) {
return reject({code: 404, message: ''});
}
context.rendered = () => {
context.state = store.state;
};
return resolve(app);
});
router.onError(e => {
reportError(e);
return reject({code: 500, message: ''});
});
});
};