index.vue 760 B

1234567891011121314151617181920212223242526272829303132333435
  1. <template>
  2. <div class="error">
  3. error page
  4. <div>
  5. <a-button
  6. type="primary"
  7. @click="toBackHandle"
  8. >
  9. 返回
  10. </a-button>
  11. </div>
  12. </div>
  13. </template>
  14. <script lang="ts" setup>
  15. import { ref } from 'vue';
  16. import { useRoute, useRouter } from 'vue-router';
  17. const route = useRoute()
  18. const router = useRouter()
  19. const text = ref('error page')
  20. const { redirectedFrom } = route
  21. if (redirectedFrom?.name === 'NotFound') {
  22. text.value = '404 page'
  23. }
  24. const toBackHandle = () => {
  25. // 这里判断大于2是因为window.open跳转的是长度是1,新开标签页再输入地址是长度是2
  26. if (history.length > 2) {
  27. router.back()
  28. } else {
  29. window.location.href = '/'
  30. }
  31. }
  32. </script>
  33. <style scoped>
  34. </style>