You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
43 lines
1.3 KiB
var routes = [];
|
|
const router = new VueRouter();
|
|
router.beforeEach((to, from, next) => {
|
|
if (to.path !== '/router/login.html') {
|
|
var isAuthenticated = false;
|
|
if (store.state.token.accessToken) {
|
|
var jwt = jwt_decode(store.state.token.accessToken);
|
|
isAuthenticated = jwt.exp * 1000 >= new Date().getTime();
|
|
}
|
|
if (!isAuthenticated) {
|
|
store.commit('logout');
|
|
setTimeout(function () {
|
|
router.push('/router/login.html');
|
|
}, 1000);
|
|
return;
|
|
}
|
|
}
|
|
var url = to.path === '/' ? '/router/home.html' : to.path;
|
|
var name = url.replace(/\//g, "-").replace(/\./g, "-").substring(1);
|
|
var route = routes[name];
|
|
if (!route) {
|
|
axios.get(url).then(function (response) {
|
|
var model = parseModel(response);
|
|
route = {
|
|
name: name,
|
|
path: to.path,
|
|
component: model,
|
|
meta: model.meta
|
|
};
|
|
router.addRoutes([route]);
|
|
routes[name] = route;
|
|
router.push({ path: to.path, query: to.query });
|
|
});
|
|
}
|
|
else {
|
|
if (to.path === from.path) {
|
|
router.push({ path: '/router/shared/redirect.html', query: { url: to.fullPath } })
|
|
}
|
|
else {
|
|
next();
|
|
}
|
|
}
|
|
}); |