ivancic_josip
ivancic_josip
NNuxt
Created by ivancic_josip on 9/17/2024 in #❓・help
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>
3 replies