mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-04 16:50:27 +00:00
use /a/{id} as redirect
This commit is contained in:
parent
60db244c66
commit
a5c59243c4
2 changed files with 43 additions and 34 deletions
|
@ -4,39 +4,6 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const api = useUserApi();
|
|
||||||
const toast = useNotifier();
|
|
||||||
|
|
||||||
const assetId = computed<string>(() => route.params.id as string);
|
const assetId = computed<string>(() => route.params.id as string);
|
||||||
|
await navigateTo("/assets/" + assetId.value, { replace: true, redirectCode: 301 });
|
||||||
const { pending, data: items } = useLazyAsyncData(`asset/${assetId.value}`, async () => {
|
|
||||||
const { data, error } = await api.assets.get(assetId.value);
|
|
||||||
if (error) {
|
|
||||||
toast.error("Failed to load asset");
|
|
||||||
navigateTo("/home");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (data.total) {
|
|
||||||
case 0:
|
|
||||||
toast.error("Asset not found");
|
|
||||||
navigateTo("/home");
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
navigateTo(`/item/${data.items[0].id}`);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return data.items;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
|
||||||
<BaseContainer>
|
|
||||||
<section v-if="!pending">
|
|
||||||
<BaseSectionHeader class="mb-5"> This Asset Id is associated with multiple items</BaseSectionHeader>
|
|
||||||
<div class="grid gap-2 grid-cols-1 sm:grid-cols-2">
|
|
||||||
<ItemCard v-for="item in items" :key="item.id" :item="item" />
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</BaseContainer>
|
|
||||||
</template>
|
|
||||||
|
|
42
frontend/pages/assets/[id].vue
Normal file
42
frontend/pages/assets/[id].vue
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
definePageMeta({
|
||||||
|
middleware: ["auth"],
|
||||||
|
});
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
const api = useUserApi();
|
||||||
|
const toast = useNotifier();
|
||||||
|
|
||||||
|
const assetId = computed<string>(() => route.params.id as string);
|
||||||
|
|
||||||
|
const { pending, data: items } = useLazyAsyncData(`asset/${assetId.value}`, async () => {
|
||||||
|
const { data, error } = await api.assets.get(assetId.value);
|
||||||
|
if (error) {
|
||||||
|
toast.error("Failed to load asset");
|
||||||
|
navigateTo("/home");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (data.total) {
|
||||||
|
case 0:
|
||||||
|
toast.error("Asset not found");
|
||||||
|
navigateTo("/home");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
navigateTo(`/item/${data.items[0].id}`, { replace: true, redirectCode: 302 });
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return data.items;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<BaseContainer>
|
||||||
|
<section v-if="!pending">
|
||||||
|
<BaseSectionHeader class="mb-5"> This Asset Id is associated with multiple items</BaseSectionHeader>
|
||||||
|
<div class="grid gap-2 grid-cols-1 sm:grid-cols-2">
|
||||||
|
<ItemCard v-for="item in items" :key="item.id" :item="item" />
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</BaseContainer>
|
||||||
|
</template>
|
Loading…
Add table
Add a link
Reference in a new issue