[main] manage VueRouter hook to pre-load page data before loading page content
This commit is contained in:
parent
a68f94d76d
commit
d56e2810a1
|
@ -4,19 +4,36 @@ import auth_wrapper from './vue/auth/wrapper.vue'
|
|||
import noauth_wrapper from './vue/noauth/wrapper.vue'
|
||||
|
||||
|
||||
/* (1) Setup Vue, VueRouter, Authentication lib */
|
||||
/* (1) Setup: Vue, VueRouter, Authentication, ClientDriver-s */
|
||||
require('./setup.js');
|
||||
/* (2) Get appropriate page data */
|
||||
|
||||
|
||||
/* (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.auth) ? 'auth' : 'noauth';
|
||||
let page_file = gs.get.router.history.current.name || gs.get.routes[auth_folder][0].name;
|
||||
|
||||
/* (3) Load page script */
|
||||
// {3} Load page script //
|
||||
require(`./page/${auth_folder}/${page_file}.js`);
|
||||
console.log(`./page/${auth_folder}/${page_file}.js`);
|
||||
|
||||
/* (4) Select appropriate wrapper */
|
||||
// {4} Let VueRouter do the magic //
|
||||
next();
|
||||
|
||||
});
|
||||
|
||||
|
||||
/* (3) Select appropriate wrapper */
|
||||
const wrapper = (gs.get.auth) ? auth_wrapper : noauth_wrapper;
|
||||
|
||||
/* (5) Render view */
|
||||
|
||||
/* (4) Render view */
|
||||
Vue.use(VueRouter);
|
||||
new Vue({
|
||||
el: '#vue',
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
|
Loading…
Reference in New Issue