routing inside url
This commit is contained in:
parent
2d0fb30558
commit
6247c385c3
15 changed files with 278 additions and 203 deletions
24
src/router/adminGuard.ts
Normal file
24
src/router/adminGuard.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import NProgress from "nprogress";
|
||||
import { useAbilityStore } from "../stores/ability";
|
||||
import { useNavigationStore } from "../stores/admin/navigation";
|
||||
|
||||
export async function abilityAndNavUpdate(to: any, from: any, next: any) {
|
||||
NProgress.start();
|
||||
const ability = useAbilityStore();
|
||||
const navigation = useNavigationStore();
|
||||
|
||||
let type = to.meta.type;
|
||||
let section = to.meta.section;
|
||||
let module = to.meta.module;
|
||||
|
||||
navigation.activeNavigation = to.name.split("-")[1];
|
||||
navigation.activeLink = to.name.split("-")[2];
|
||||
|
||||
if (ability.can(type, section, module)) {
|
||||
NProgress.done();
|
||||
next();
|
||||
} else {
|
||||
NProgress.done();
|
||||
next(false);
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@ import Login from "../views/Login.vue";
|
|||
import { isAuthenticated } from "./authGuards";
|
||||
import { loadAccountData } from "./accountGuard";
|
||||
import { isSetup } from "./setupGuard";
|
||||
import { abilityAndNavUpdate } from "./adminGuard";
|
||||
import type { PermissionType, PermissionSection, PermissionModule } from "../types/permissionTypes";
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
|
@ -41,6 +43,110 @@ const router = createRouter({
|
|||
name: "admin",
|
||||
component: () => import("../views/admin/View.vue"),
|
||||
beforeEnter: [isAuthenticated],
|
||||
children: [
|
||||
{
|
||||
path: "",
|
||||
name: "admin-default",
|
||||
component: () => import("../views/RouterView.vue"),
|
||||
},
|
||||
{
|
||||
path: "club",
|
||||
name: "admin-club",
|
||||
component: () => import("../views/RouterView.vue"),
|
||||
meta: { type: "read", section: "club" },
|
||||
beforeEnter: [abilityAndNavUpdate],
|
||||
children: [
|
||||
{
|
||||
path: "",
|
||||
name: "admin-club-default",
|
||||
component: () => import("../views/admin/ViewSelect.vue"),
|
||||
},
|
||||
{
|
||||
path: "members",
|
||||
name: "admin-club-members",
|
||||
component: () => import("../views/admin/members/Overview.vue"),
|
||||
},
|
||||
{
|
||||
path: "calendar",
|
||||
name: "admin-club-calendar",
|
||||
component: () => import("../views/admin/members/Overview.vue"),
|
||||
},
|
||||
{
|
||||
path: "newsletter",
|
||||
name: "admin-club-newsletter",
|
||||
component: () => import("../views/admin/members/Overview.vue"),
|
||||
},
|
||||
{
|
||||
path: "protocol",
|
||||
name: "admin-club-protocol",
|
||||
component: () => import("../views/admin/members/Overview.vue"),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "settings",
|
||||
name: "admin-settings",
|
||||
component: () => import("../views/RouterView.vue"),
|
||||
meta: { type: "read", section: "settings" },
|
||||
beforeEnter: [abilityAndNavUpdate],
|
||||
children: [
|
||||
{
|
||||
path: "",
|
||||
name: "admin-settings-default",
|
||||
component: () => import("../views/admin/ViewSelect.vue"),
|
||||
},
|
||||
{
|
||||
path: "qualification",
|
||||
name: "admin-settings-qualification",
|
||||
component: () => import("../views/admin/members/Overview.vue"),
|
||||
},
|
||||
{
|
||||
path: "award",
|
||||
name: "admin-settings-award",
|
||||
component: () => import("../views/admin/members/Overview.vue"),
|
||||
},
|
||||
{
|
||||
path: "executive-position",
|
||||
name: "admin-settings-executive_position",
|
||||
component: () => import("../views/admin/members/Overview.vue"),
|
||||
},
|
||||
{
|
||||
path: "communication",
|
||||
name: "admin-settings-communication",
|
||||
component: () => import("../views/admin/members/Overview.vue"),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "user",
|
||||
name: "admin-user",
|
||||
component: () => import("../views/RouterView.vue"),
|
||||
meta: { type: "read", section: "user" },
|
||||
beforeEnter: [abilityAndNavUpdate],
|
||||
children: [
|
||||
{
|
||||
path: "",
|
||||
name: "admin-user-default",
|
||||
component: () => import("../views/admin/ViewSelect.vue"),
|
||||
},
|
||||
{
|
||||
path: "user",
|
||||
name: "admin-user-user",
|
||||
component: () => import("../views/admin/user/User.vue"),
|
||||
},
|
||||
{
|
||||
path: "role",
|
||||
name: "admin-user-role",
|
||||
component: () => import("../views/admin/user/Role.vue"),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: ":pathMatch(.*)*",
|
||||
name: "admin-404",
|
||||
component: () => import("../views/notFound.vue"),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "/nopermissions",
|
||||
|
@ -56,3 +162,11 @@ const router = createRouter({
|
|||
});
|
||||
|
||||
export default router;
|
||||
|
||||
declare module "vue-router" {
|
||||
interface RouteMeta {
|
||||
type?: PermissionType | "admin";
|
||||
section?: PermissionSection;
|
||||
module?: PermissionModule;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue