feat: redirect to first channel in list when going to server url
This commit is contained in:
parent
5011affd49
commit
abf3b248c4
2 changed files with 18 additions and 2 deletions
15
middleware/server.ts
Normal file
15
middleware/server.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import type { ChannelResponse } from "~/types/interfaces";
|
||||||
|
|
||||||
|
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||||
|
const { fetchChannels } = useApi();
|
||||||
|
|
||||||
|
const guildId = to.params.serverId as string;
|
||||||
|
|
||||||
|
const channels: ChannelResponse[] | undefined = await fetchChannels(guildId);
|
||||||
|
console.log("channels:", channels);
|
||||||
|
|
||||||
|
if (channels && channels.length > 0) {
|
||||||
|
console.log("wah");
|
||||||
|
return await navigateTo(`/servers/${guildId}/channels/${channels[0].uuid}`, { replace: true });
|
||||||
|
}
|
||||||
|
})
|
|
@ -5,8 +5,9 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
const guild = await fetchWithApi(`/guilds/${useRoute().params.serverId}`);
|
definePageMeta({
|
||||||
console.log("guild:", guild);
|
middleware: "server"
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue