<template>
  <a-breadcrumb class="breadcrumb">
    <a-breadcrumb-item v-for="(item, index) in breadList" :key="item.name">
      <router-link v-if="item.name != name && index != 1" :to="{ path: item.path === '' ? '/' : item.path }">{{
        $lang(item.meta.title)
      }}</router-link>
      <span v-else>{{ $lang(item.meta.title) }}</span>
    </a-breadcrumb-item>
  </a-breadcrumb>
</template>

<script>
export default {
  data() {
    return {
      name: '',
      breadList: [],
    }
  },
  created() {
    this.getBreadcrumb()
  },
  methods: {
    getBreadcrumb() {
      this.breadList = []

      this.name = this.$route.name
      var i=0;
      this.$route.matched.forEach((item) => {
        if(i==0){
          //continue;
        }else if(i==1){
         this.breadList.push({...item,name:'home',path:'/home',meta:{title:this.$lang('首页')}})
        }else{
          this.breadList.push(item)
        }
        //item.name !== 'index' && this.breadList.push(item)
        i++;
        //this.breadList.push(item)
      })
    },
  },
  watch: {
    $route() {
      this.getBreadcrumb()
    },
  },
}
</script>

<style scoped>
</style>
