Files
Nexior/src/router/index.ts
T
2023-04-06 20:13:16 +08:00

48 lines
945 B
TypeScript

import { createRouter, createWebHistory } from 'vue-router';
import service from './service';
import auth from './auth';
import console from './console';
import conversation from './conversation';
import document from './document';
import store from '@/store';
import { ROUTE_AUTH_LOGIN, ROUTE_INDEX, ROUTE_SERVICE_LIST } from './constants';
const routes = [
{
path: '/',
name: ROUTE_INDEX,
redirect: {
name: ROUTE_SERVICE_LIST
}
},
service,
auth,
console,
document,
conversation
];
const router = createRouter({
history: createWebHistory(),
routes
});
router.beforeEach((to, from, next) => {
if (to.matched.some((record) => record.meta.auth)) {
if (!store.getters.authenticated) {
next({
name: ROUTE_AUTH_LOGIN,
query: { redirect: to.fullPath }
});
} else {
next();
}
} else {
next();
}
});
export default router;
export * from './constants';