check mission existance before navigation
This commit is contained in:
parent
3b2a0ca231
commit
a9a32801be
4 changed files with 22 additions and 2 deletions
|
@ -7,6 +7,7 @@ import { abilityAndNavUpdate } from "./adminGuard";
|
|||
import type { PermissionType, PermissionSection, PermissionModule } from "@/types/permissionTypes";
|
||||
import { config } from "../config";
|
||||
import { setBackupPage } from "./backupGuard";
|
||||
import { checkMissionExists } from "./missionGuard";
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
|
@ -112,7 +113,7 @@ const router = createRouter({
|
|||
name: "admin-operation-mission-form",
|
||||
component: () => import("@/views/admin/operation/mission/MissionOverview.vue"),
|
||||
meta: { type: "read", section: "operation", module: "mission" },
|
||||
beforeEnter: [abilityAndNavUpdate],
|
||||
beforeEnter: [abilityAndNavUpdate, checkMissionExists],
|
||||
props: true,
|
||||
},
|
||||
],
|
||||
|
|
14
src/router/missionGuard.ts
Normal file
14
src/router/missionGuard.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { useMissionStore } from "../stores/admin/operation/mission";
|
||||
|
||||
export async function checkMissionExists(to: any, from: any, next: any) {
|
||||
const mission = useMissionStore();
|
||||
|
||||
await mission
|
||||
.fetchMissionById(to.params?.id ?? "")
|
||||
.then(() => {
|
||||
next();
|
||||
})
|
||||
.catch(() => {
|
||||
next({ name: "admin-operation-mission" });
|
||||
});
|
||||
}
|
|
@ -61,7 +61,9 @@ http.interceptors.response.use(
|
|||
.then(() => {
|
||||
return http(originalRequest);
|
||||
})
|
||||
.catch(() => {});
|
||||
.catch(() => {
|
||||
router.push({ name: "login" });
|
||||
});
|
||||
}
|
||||
|
||||
const notificationStore = useNotificationStore();
|
||||
|
|
|
@ -40,6 +40,9 @@ export const useMissionStore = defineStore("mission", {
|
|||
this.loading = "failed";
|
||||
});
|
||||
},
|
||||
fetchMissionById(id: string): Promise<AxiosResponse<any, any>> {
|
||||
return http.get(`/admin/mission/${id}`);
|
||||
},
|
||||
prependMission(mission: MissionShortViewModel) {
|
||||
this.missions.unshift(mission);
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue