Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Commit 42ecdd2

Browse files
committed
1. implement code splitting by routes https://router.vuejs.org/guide/advanced/lazy-loading.html
2. change webpack config to workaround vuejs/vue-cli#1669. Can remove after update vue-cli to future release 3. move Landing screen login to main.js 4. add loading indicator and error handling for async route
1 parent 47cf2c1 commit 42ecdd2

File tree

4 files changed

+102
-49
lines changed

4 files changed

+102
-49
lines changed

src/main.js

+37-7
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ import Vuelidate from 'vuelidate';
99
import mixpanel from 'mixpanel-browser';
1010

1111
// require styles
12-
// eslint-disable-next-line
1312
import 'swiper/dist/css/swiper.css';
1413
import VueAwesomeSwiper from 'vue-awesome-swiper';
1514

1615
import App from './App';
1716
import router from './router';
18-
1917
import store from './store';
2018
import i18n from './localization';
2119

2220
import fixVirtualKeyboardGlitch from './helpers/fixVirtualKeyboardGlitch';
2321
import inobounce from './helpers/inobounce';
2422

23+
import { RouteDef } from '@/constants';
24+
import { SET_IS_LOADING, OPEN_ERROR_PROMPT } from '@/store/modules/common';
25+
2526
Vue.config.productionTip = false;
2627
Vue.use(VueMaterial);
2728
Vue.use(Vuelidate);
@@ -30,14 +31,43 @@ Vue.use(VueAwesomeSwiper);
3031

3132
mixpanel.init('c5e652bf9ccc28d929ee1c8184a0f76b');
3233

33-
/* eslint-disable no-new */
34-
new Vue({
35-
el: '#app',
34+
const app = new Vue({
3635
store,
3736
i18n,
3837
router,
39-
components: { App },
40-
template: '<App/>',
38+
render: h => h(App),
39+
});
40+
41+
const landingRoute = RouteDef.BetaTesting;
42+
const originalLocation = router.resolve(window.location.href);
43+
router.replace({
44+
...originalLocation.location,
45+
...landingRoute,
46+
});
47+
48+
router.onReady(() => {
49+
app.$mount('#app');
50+
});
51+
52+
router.beforeEach((to, from, next) => {
53+
store.commit(SET_IS_LOADING, true);
54+
next();
55+
});
56+
57+
router.afterEach(() => {
58+
store.commit(SET_IS_LOADING, false);
59+
});
60+
61+
router.onError(() => {
62+
store.commit(SET_IS_LOADING, false);
63+
store.dispatch(OPEN_ERROR_PROMPT, {
64+
message: {
65+
messageId: 'message.common.unknow_error',
66+
},
67+
title: {
68+
messageId: 'message.common.error_title',
69+
},
70+
});
4171
});
4272

4373
fixVirtualKeyboardGlitch();

src/router/index.js

+57-40
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,68 @@ import { RouteDef } from '@/constants';
66

77
import AppLayout from '@/container/AppLayout';
88

9-
import Home from '@/screens/Home';
10-
import BetaTesting from '@/screens/BetaTesting';
11-
import Login from '@/screens/Login';
12-
import Register from '@/screens/Register';
13-
import ForgetPassword from '@/screens/ForgetPassword';
14-
import Settings from '@/screens/setting/Settings';
15-
import UserSettings from '@/screens/setting/UserSettings';
16-
import PriceUnits from '@/screens/setting/PriceUnits';
17-
import ReportProblem from '@/screens/setting/ReportProblem';
18-
import ReportProblemSuccess from '@/screens/setting/ReportProblemSuccess';
19-
import LegalAndPrivacy from '@/screens/setting/LegalAndPrivacy';
20-
import AddPhoneNumberInputPage from '@/screens/phone/AddPhoneNumberInputPage';
21-
import ChangePhoneNumberInputPage from '@/screens/phone/ChangePhoneNumberInputPage';
22-
import AddPhoneNumberVerifyPage from '@/screens/phone/AddPhoneNumberVerifyPage';
23-
import ChangePhoneNumberVerifyPage from '@/screens/phone/ChangePhoneNumberVerifyPage';
24-
import PhoneNumberVerifyPage from '@/screens/phone/PhoneNumberVerifyPage';
25-
import PinCodeSetup from '@/screens/pincode/PinCodeSetup';
26-
import PinCodeConfirm from '@/screens/pincode/PinCodeConfirm';
27-
import PinCodeForgot from '@/screens/pincode/PinCodeForgot';
28-
import Tutorial from '@/screens/Tutorial';
29-
import AccountDetail from '@/screens/AccountDetail';
30-
import TransactionDetail from '@/screens/TransactionDetail';
31-
import TransferList from '@/screens/transfer/TransferList';
32-
import TransferEmail from '@/screens/transfer/TransferEmail';
33-
import TransferEthWallet from '@/screens/transfer/TransferEthWallet';
34-
import TransferReview from '@/screens/transfer/TransferReview';
35-
import TransferSuccess from '@/screens/transfer/TransferSuccess';
36-
import QrCodeScanPage from '@/screens/QRCodeScanPage';
37-
import EarnMDT from '@/screens/EarnMDT';
38-
import WebView from '@/screens/WebView';
9+
const Home = () => import('@/screens/Home');
10+
const BetaTesting = () => import('@/screens/BetaTesting');
11+
const Login = () => import('@/screens/Login');
12+
const Register = () => import('@/screens/Register');
13+
const ForgetPassword = () => import('@/screens/ForgetPassword');
14+
const Settings = () => import('@/screens/setting/Settings');
15+
const UserSettings = () => import('@/screens/setting/UserSettings');
16+
const PriceUnits = () => import('@/screens/setting/PriceUnits');
17+
const ReportProblem = () =>
18+
import(/* webpackChunkName: "report-problem" */ '@/screens/setting/ReportProblem');
19+
const ReportProblemSuccess = () =>
20+
import(/* webpackChunkName: "report-problem" */ '@/screens/setting/ReportProblemSuccess');
21+
const LegalAndPrivacy = () => import('@/screens/setting/LegalAndPrivacy');
22+
const AddPhoneNumberInputPage = () =>
23+
import(/* webpackChunkName: "phone-number" */ '@/screens/phone/AddPhoneNumberInputPage');
24+
const ChangePhoneNumberInputPage = () =>
25+
import(/* webpackChunkName: "phone-number" */ '@/screens/phone/ChangePhoneNumberInputPage');
26+
const AddPhoneNumberVerifyPage = () =>
27+
import(/* webpackChunkName: "phone-number" */ '@/screens/phone/AddPhoneNumberVerifyPage');
28+
const ChangePhoneNumberVerifyPage = () =>
29+
import(/* webpackChunkName: "phone-number" */ '@/screens/phone/ChangePhoneNumberVerifyPage');
30+
const PhoneNumberVerifyPage = () =>
31+
import(/* webpackChunkName: "phone-number" */ '@/screens/phone/PhoneNumberVerifyPage');
32+
const PinCodeSetup = () =>
33+
import(/* webpackChunkName: "pin-code" */ '@/screens/pincode/PinCodeSetup');
34+
const PinCodeConfirm = () =>
35+
import(/* webpackChunkName: "pin-code" */ '@/screens/pincode/PinCodeConfirm');
36+
const PinCodeForgot = () =>
37+
import(/* webpackChunkName: "pin-code" */ '@/screens/pincode/PinCodeForgot');
38+
const Tutorial = () => import('@/screens/Tutorial');
39+
const AccountDetail = () =>
40+
import(/* webpackChunkName: "account-detail" */ '@/screens/AccountDetail');
41+
const TransactionDetail = () =>
42+
import(/* webpackChunkName: "account-detail" */ '@/screens/TransactionDetail');
43+
const TransferList = () =>
44+
import(/* webpackChunkName: "transfer" */ '@/screens/transfer/TransferList');
45+
const TransferEmail = () =>
46+
import(/* webpackChunkName: "transfer" */ '@/screens/transfer/TransferEmail');
47+
const TransferEthWallet = () =>
48+
import(/* webpackChunkName: "transfer" */ '@/screens/transfer/TransferEthWallet');
49+
const TransferReview = () =>
50+
import(/* webpackChunkName: "transfer" */ '@/screens/transfer/TransferReview');
51+
const TransferSuccess = () =>
52+
import(/* webpackChunkName: "transfer" */ '@/screens/transfer/TransferSuccess');
53+
const QrCodeScanPage = () =>
54+
import(/* webpackChunkName: "transfer" */ '@/screens/QRCodeScanPage');
55+
const EarnMDT = () => import('@/screens/EarnMDT');
56+
const WebView = () => import('@/screens/WebView');
57+
58+
/**
59+
* example code to fail async loading of route
60+
*
61+
const Component = () => {
62+
throw new Error('load route failed');
63+
};
64+
*/
3965

4066
import BetaTestingHeader from '@/components/header/BetaTestingHeader';
4167

4268
Vue.use(Router);
4369
Vue.use(Meta);
4470

45-
const landingRoute = RouteDef.BetaTesting;
46-
4771
const router = new Router({
4872
mode: 'history',
4973
routes: [
@@ -61,7 +85,7 @@ const router = new Router({
6185
},
6286
{
6387
path: RouteDef.AutoLogin.path,
64-
redirect: landingRoute,
88+
redirect: RouteDef.Home,
6589
},
6690
{
6791
path: RouteDef.BetaTesting.path,
@@ -224,11 +248,4 @@ const router = new Router({
224248
],
225249
});
226250

227-
// redirect to landing page
228-
const originalLocation = router.resolve(window.location.href);
229-
router.replace({
230-
...originalLocation.location,
231-
...landingRoute,
232-
});
233-
234251
export default router;

src/screens/Home.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ export default {
140140
const emailsStr = this.$route.query.emails;
141141
const needExit = this.$route.query.needexit;
142142
143+
// clear url
144+
this.$router.replace(RouteDef.Home);
145+
143146
this.setNeedExitBtn(needExit);
144147
this.autoLogin(appID, tokensStr, emailsStr, this.$i18n.locale);
145148
}
@@ -151,8 +154,6 @@ export default {
151154
this.setIsUserAcctionsDirty(false);
152155
}
153156
154-
// clear url
155-
this.$router.replace(RouteDef.Home);
156157
trackEvent('Home view', { 'Email Number': this.allUsers.length });
157158
},
158159
methods: {

vue.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,10 @@ module.exports = {
1818
}
1919
return args;
2020
});
21+
22+
config.plugin("html").tap(args => {
23+
args[0].chunksSortMode = "none";
24+
return args;
25+
})
2126
}
2227
};

0 commit comments

Comments
 (0)