1 | import Vue from 'vue'
|
2 | import { createApp } from './app.js'
|
3 | import { callAsyncRecursive } from './ssr/callAsyncRecursive.js'
|
4 | import { registerStoreModules } from './ssr/registerStoreModules.js'
|
5 | import root from 'src/app.vue'
|
6 | import Progress from 'src/components/progress.vue'
|
7 |
|
8 |
|
9 | const progress = Vue.prototype.$progress = new Vue(Progress).$mount()
|
10 | document.body.appendChild(progress.$el)
|
11 |
|
12 |
|
13 | const { app, router, store } = createApp()
|
14 |
|
15 |
|
16 |
|
17 | if (window.__INITIAL_STATE__) {
|
18 | store.replaceState(window.__INITIAL_STATE__)
|
19 | }
|
20 |
|
21 |
|
22 | if (store.state.$access_token) {
|
23 | app.$cubic.setAccessToken(store.state.$access_token)
|
24 | delete store.state.$access_token
|
25 | }
|
26 | if (store.state.$refresh_token) {
|
27 | app.$cubic.setRefreshToken(store.state.$refresh_token)
|
28 | delete store.state.$refresh_token
|
29 | }
|
30 |
|
31 |
|
32 | router.onReady(() => {
|
33 | const routerView = router.getMatchedComponents()
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | registerStoreModules(root, store)
|
39 | routerView.map(component => registerStoreModules(component, store, true))
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | router.beforeResolve(async (to, from, next) => {
|
46 | const matched = router.getMatchedComponents(to)
|
47 |
|
48 |
|
49 | registerStoreModules(root, store)
|
50 | matched.map(component => registerStoreModules(component, store, true))
|
51 |
|
52 |
|
53 | let progressStarted
|
54 | await Promise.all(matched.map(c => callAsyncRecursive(c, store, router, to, progress, progressStarted)))
|
55 |
|
56 |
|
57 | progress.finish()
|
58 | next()
|
59 | })
|
60 | app.$mount('#app')
|
61 | })
|