index.jsx 798 B

123456789101112131415161718192021222324252627
  1. import { defineComponent, KeepAlive } from 'vue'
  2. import { getFullPathWithoutHash } from '../helper'
  3. export default defineComponent({
  4. name: 'CipRouterView',
  5. props: {
  6. viewKey: String,
  7. noViewKey: { type: Boolean, default: undefined },
  8. cacheList: Array
  9. },
  10. setup (props) {
  11. return () => (
  12. <router-view>
  13. {{
  14. default: ({ Component, route, ...args }) => {
  15. // TODO: 直接修改name可能导致的问题位置
  16. if (Component && !props.noViewKey) {
  17. Component.type.name = getFullPathWithoutHash(route.fullPath)
  18. }
  19. return <KeepAlive include={props.cacheList}>
  20. {Component && <Component key={props.viewKey}/>}
  21. </KeepAlive>
  22. }
  23. }}
  24. </router-view>
  25. )
  26. }
  27. })