Files
dtv/app/composables/useGoBackOrHome.ts
2025-10-31 19:10:01 +07:00

21 lines
499 B
TypeScript

import { useRouter } from 'vue-router';
import { ref } from 'vue';
export const useGoBackOrHome = () => {
const router = useRouter();
const canGoBack = ref(false);
if (typeof window !== 'undefined') {
canGoBack.value = window.history.length > 1;
}
const goBack = () => {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
canGoBack.value && window.history.length > 1
? router.back()
: router.push('/');
};
return { goBack, canGoBack };
};