<script lang='ts' setup>
import { chevronBackOutline } from "ionicons/icons";

const { text = "返回" } = defineProps<{
  text?: string;
}>();
const router = useRouter();

function onBack() {
  if (window.history.length > 1) {
    router.back();
  }
  else {
    router.replace("/");
  }
}
</script>

<template>
  <button class="z-1 flex items-center" @click="onBack">
    <ion-icon :icon="chevronBackOutline" class="text-2xl" />
    <span v-if="text" class="text-base">{{ text }}</span>
  </button>
</template>

<style lang='css' scoped></style>
