47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
import Vue from "vue";
|
|
import store from "./store.js";
|
|
import VueRouter from "vue-router";
|
|
import Carrito from "./layout/Carrito.vue";
|
|
import Inicio from "./layout/Inicio.vue";
|
|
import Login from "./layout/Login.vue";
|
|
import Usuario from "./layout/Usuario.vue";
|
|
import Equipo from "./layout/Equipo.vue";
|
|
import Multa from "./layout/Multa.vue";
|
|
import Blacklist from "./layout/Blacklist.vue";
|
|
import Bans from "./layout/Bans.vue";
|
|
|
|
const routes = [
|
|
{ path: "/", component: Inicio, name: "inicio" },
|
|
{ path: "/login", component: Login, name: "login", meta: { isPublic: true } },
|
|
{ path: "/carrito", component: Carrito, name: "carrito" },
|
|
{ path: "/usuario", component: Usuario, name: "usuario" },
|
|
{ path: "/equipo/", component: Equipo, name: "equipo" },
|
|
{ path: "/multa", component: Multa, name: "multa" },
|
|
{ path: "/blacklist", component: Blacklist, name: "blacklist" },
|
|
{ path: "/bans", component: Bans, name: "bans" }
|
|
];
|
|
Vue.use(VueRouter);
|
|
|
|
const router = new VueRouter({ routes });
|
|
|
|
const isAuthenticated = function() {
|
|
return store.getters.isLoggedIn;
|
|
};
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
if (to.name === "blacklist") {
|
|
return next();
|
|
}
|
|
if (!to.meta.isPublic && !isAuthenticated()) {
|
|
return next({ name: "login" });
|
|
}
|
|
|
|
if (to.name === "login" && isAuthenticated()) {
|
|
return next({ name: "home" });
|
|
}
|
|
|
|
return next();
|
|
});
|
|
|
|
export default router;
|