Skip to content

Commit e87c80e

Browse files
committed
Refactor app init routines to load config/i18n before main app mount.
Move config/language loading outside the main Vue() instance mount as the app dependencies require i18n before they are mounted. This commit moves config/language loading outside the app routines to plain API calls, which on success, initialize and mount the main view App instance.
1 parent 76a86fa commit e87c80e

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

frontend/src/main.js

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ const i18n = new VueI18n();
1515
Vue.use(Buefy, {});
1616
Vue.config.productionTip = false;
1717

18-
// Globals.
19-
Vue.prototype.$utils = new Utils(i18n);
20-
Vue.prototype.$api = api;
18+
2119

2220
// Setup the router.
2321
router.beforeEach((to, from, next) => {
@@ -30,12 +28,13 @@ router.beforeEach((to, from, next) => {
3028

3129
router.afterEach((to) => {
3230
Vue.nextTick(() => {
33-
const t = to.meta.title ? `${i18n.tc(to.meta.title, 0)} /` : '';
31+
const t = to.meta.title && i18n.te(to.meta.title) ? `${i18n.tc(to.meta.title, 0)} /` : '';
3432
document.title = `${t} listmonk`;
3533
});
3634
});
3735

38-
new Vue({
36+
37+
const v = new Vue({
3938
router,
4039
store,
4140
i18n,
@@ -45,20 +44,28 @@ new Vue({
4544
isLoaded: false,
4645
},
4746

48-
methods: {
49-
loadConfig() {
50-
api.getServerConfig().then((data) => {
51-
api.getLang(data.lang).then((lang) => {
52-
i18n.locale = data.lang;
53-
i18n.setLocaleMessage(i18n.locale, lang);
54-
this.isLoaded = true;
55-
});
56-
});
57-
},
47+
mounted() {
48+
v.isLoaded = true;
5849
},
50+
});
5951

60-
created() {
61-
this.loadConfig();
62-
api.getSettings();
63-
},
64-
}).$mount('#app');
52+
53+
// Load server side config and language before mounting the app.
54+
api.getServerConfig().then((data) => {
55+
api.getLang(data.lang).then((lang) => {
56+
i18n.locale = data.lang;
57+
i18n.setLocaleMessage(i18n.locale, lang);
58+
59+
Vue.prototype.$utils = new Utils(i18n);
60+
Vue.prototype.$api = api;
61+
62+
// Set the page title after i18n has loaded.
63+
const to = router.history.current;
64+
const t = to.meta.title ? `${i18n.tc(to.meta.title, 0)} /` : '';
65+
document.title = `${t} listmonk`;
66+
67+
v.$mount('#app');
68+
});
69+
});
70+
71+
api.getSettings();

0 commit comments

Comments
 (0)