<template>
  <div class="home">
    <router-view></router-view>
  </div>
</template>

<script>
import { roleRouters } from "../router";
// import { humpFormat } from "@/plugins/utils";

export default {
  name: "home",
  data() {
    return {
      validRouters: []
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      const roleCode = "ADMIN";
      this.getValidRouters(roleRouters[roleCode]);
      // console.log(this.$route);

      if (this.$route.name === "Home") {
        // TODO:根据角色跳转不同的路由
        // this.$router.replace({
        //   name: humpFormat([roleCode, "home"])
        // });
      } else {
        if (!this.validRouters.includes(this.$route.name)) {
          this.$router.replace({
            name: "404"
          });
        }
      }
    },
    getValidRouters(routers) {
      routers.map(router => {
        this.validRouters.push(router.name);
        if (router["children"]) this.getValidRouters(router["children"]);
      });
    }
  }
};
</script>
