discord-client/webpack/main.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

import Vue from 'vue'
import VueRouter from 'vue-router'
import auth_wrapper from './vue/auth/wrapper.vue'
import noauth_wrapper from './vue/noauth/wrapper.vue'
2018-03-21 17:44:27 +00:00
/* (1) Setup: Vue, VueRouter, Authentication, ClientDriver-s */
require('./setup.js');
2018-03-21 17:44:27 +00:00
/* (2) Set router hooks to load page data before loading content */
gs.get.router.beforeEach((to, from, next) => {
// {1} Ignore null name //
if( to.name == null )
next();
// {2} Get appropriate page location //
let auth_folder = (gs.get.authed) ? 'auth' : 'noauth';
let page_file = to.name || gs.get.routes[auth_folder][0].name;
2018-04-07 13:04:13 +00:00
let fullpath = `${auth_folder}/${page_file}`;
// {3} Load page script //
2018-04-07 13:04:13 +00:00
if( fullpath === 'noauth/login')
require('./page/noauth/login.js');
else if( fullpath === 'noauth/register')
require('./page/noauth/register.js');
else if( fullpath === 'auth/channel')
require('./page/auth/channel.js');
// {4} Let VueRouter do the magic //
next();
});
/* (3) Select appropriate wrapper */
const wrapper = (gs.get.authed) ? auth_wrapper : noauth_wrapper;
2018-03-21 17:44:27 +00:00
/* (4) Render view */
2018-03-21 17:44:27 +00:00
Vue.use(VueRouter);
new Vue({
el: '#vue',
router: gs.get.router,
render(h){ return h(wrapper); }
})