import { defineComponent, KeepAlive } from 'vue'
import { getFullPathWithoutHash } from '../helper'
import { isSubApp } from '../../cip-subapp-container/micro-app/util'
export default defineComponent({
  name: 'CipRouterView',
  props: {
    viewKey: String,
    noViewKey: { type: Boolean, default: undefined },
    cacheList: Array
  },
  setup (props) {
    return () => (
      <router-view>
        {{
          default: ({ Component, route, ...args }) => {
            // TODO: 直接修改name可能导致的问题位置
            if (!isSubApp(route.name)) {
              // 不对子应用进行相关操作
              if (Component && !props.noViewKey) {
                Component.type.name = getFullPathWithoutHash(route.fullPath)
              }
            }
            return <KeepAlive include={props.cacheList}>
              {Component && <Component key={props.viewKey}/>}
            </KeepAlive>
          }
        }}
      </router-view>
    )
  }
})
