import { createRouter, createWebHistory } from "vue-router";
import { staticRouter, errorRouter } from "@/routers/modules/staticRouter";

const router = createRouter({
  history: createWebHistory(),
  routes: [...staticRouter, ...errorRouter]
});

const tableRefNames = ["proTable", "courseTable", "userTable"];

router.afterEach((to, from) => {
  if (to.matched.length === 0) return;
  const instance = to.matched[to.matched.length - 1]?.instances?.default;

  tableRefNames.forEach(refName => {
    if (instance && instance[refName]?.getTableList) {
      instance[refName].getTableList();
    }
  });
});

export default router;
