init
This commit is contained in:
20
app/composables/useGoBackOrHome.ts
Normal file
20
app/composables/useGoBackOrHome.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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 };
|
||||
};
|
||||
Reference in New Issue
Block a user