Redirecting from a route on server side

Hello, I'm not sure why this is not working, I get a 404 even though the code gets to the navigateTo call, anyone have any idea?
<script setup lang="ts">
const issn = useRoute("issn").params.issn;
const isParamIssn = issn.includes("-");

if (isParamIssn) {
await redirectToJournal();
} else {
await redirectToArticle();
}

async function redirectToJournal() {
const data = await JournalsService.fetchSingleJournalNameByIssn(issn);

if (data.nameSystem) {
navigateTo(
{
...
},
{
redirectCode: 301,
}
);
} else {
throw createError({
statusCode: 404,
});
}
}

async function redirectToArticle() {
const articleId = issn;
const data = await ArticlesService.fetchRedirectDataById(articleId);

if (data.identifier) {
navigateTo(
{
...
},
{
redirectCode: 301,
}
);
} else {
throw createError({
statusCode: 404,
});
}
}
</script>
<script setup lang="ts">
const issn = useRoute("issn").params.issn;
const isParamIssn = issn.includes("-");

if (isParamIssn) {
await redirectToJournal();
} else {
await redirectToArticle();
}

async function redirectToJournal() {
const data = await JournalsService.fetchSingleJournalNameByIssn(issn);

if (data.nameSystem) {
navigateTo(
{
...
},
{
redirectCode: 301,
}
);
} else {
throw createError({
statusCode: 404,
});
}
}

async function redirectToArticle() {
const articleId = issn;
const data = await ArticlesService.fetchRedirectDataById(articleId);

if (data.identifier) {
navigateTo(
{
...
},
{
redirectCode: 301,
}
);
} else {
throw createError({
statusCode: 404,
});
}
}
</script>
1 Reply
Aman Desai
Aman Desai4mo ago
you have to await it await navigateTo
Want results from more Discord servers?
Add your server