viewTransition.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { ViewTransitions } from '#mobile/components/transition/TransitionViewNavigation/types.ts'
  3. import { useViewTransition } from '#mobile/components/transition/TransitionViewNavigation/useViewTransition.ts'
  4. import type {
  5. NavigationGuard,
  6. RouteLocationNormalized,
  7. NavigationGuardNext,
  8. } from 'vue-router'
  9. const transitionViewGuard: NavigationGuard = (
  10. to: RouteLocationNormalized,
  11. from: RouteLocationNormalized,
  12. next: NavigationGuardNext,
  13. ) => {
  14. // For now we need to add a workaround solution with a route level for the different transition types
  15. // until the following feature was added: https://github.com/vuejs/vue-router/issues/3453.
  16. const { setViewTransition } = useViewTransition()
  17. let newViewTransition: ViewTransitions = ViewTransitions.Replace
  18. // In the case that the 'To'-Route has no level, we use the replace transition.
  19. if (to.meta?.level) {
  20. const previousLevel = from.meta?.level || 1
  21. if (previousLevel !== to.meta.level) {
  22. newViewTransition =
  23. previousLevel < to.meta.level
  24. ? ViewTransitions.Next
  25. : ViewTransitions.Prev
  26. }
  27. }
  28. setViewTransition(newViewTransition)
  29. next()
  30. }
  31. export default transitionViewGuard