N
Nuxt2mo ago
JuanMCe

Redirect inside asyncData

I want to redirect to a named route inside asyncData, my nuxt project is ssr: false I have something like this in my Page component:
async asyncData({ store, params, query, $axios, redirect }) {
// ...some logic
if (purchaseTransaction.status === 'confirmed') {
redirect({
name: 'exchange-status',
params: { id: purchaseTransaction.exchange.id },
});
}
// ...more logic
async asyncData({ store, params, query, $axios, redirect }) {
// ...some logic
if (purchaseTransaction.status === 'confirmed') {
redirect({
name: 'exchange-status',
params: { id: purchaseTransaction.exchange.id },
});
}
// ...more logic
I have a router.js file I use to extend some routes with extendRoutes in my nuxt config. My route is defined like this:
{
path: '/estado-canje/:id',
name: 'exchange-status',
component: resolve(__dirname, 'pages_ignore/exchange/status.vue'),
},
{
path: '/estado-canje/:id',
name: 'exchange-status',
component: resolve(__dirname, 'pages_ignore/exchange/status.vue'),
},
I get redirected to my home instead and I get this error in the browser console: [vue-router] Route with name 'exchange-status' does not exist I can enter the route directly without problems but I have no idea why redirect doesn't work
1 Reply
JuanMCe
JuanMCeOP2mo ago
nevermind, it was nuxtI18n renaming my routes.
Want results from more Discord servers?
Add your server