21 lines
499 B
TypeScript
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 };
|
||
|
|
};
|