Redirect.vue 581 B

12345678910111213141516171819202122232425262728
  1. <template>
  2. <div></div>
  3. </template>
  4. <script setup lang="ts">
  5. defineOptions({ name: 'Redirect' })
  6. const { currentRoute, replace } = useRouter()
  7. const { params, query } = unref(currentRoute)
  8. const { path, _redirect_type = 'path' } = params
  9. Reflect.deleteProperty(params, '_redirect_type')
  10. Reflect.deleteProperty(params, 'path')
  11. const _path = Array.isArray(path) ? path.join('/') : path
  12. if (_redirect_type === 'name') {
  13. replace({
  14. name: _path,
  15. query,
  16. params
  17. })
  18. } else {
  19. replace({
  20. path: _path.startsWith('/') ? _path : '/' + _path,
  21. query
  22. })
  23. }
  24. </script>