Home

Issue: 2019

redirect() not rendering within plugin

[issue link]

I’m using a non-ssr plugin to check something before redirecting, the only way I can get it to fire is but wrapping a Promise around the function and leaving out the resolve() within the Promise, the url updates, but the redirected page doesn’t render, just the previous page…

nuxt.config.js

plugins: [
	{ src: '~/plugins/auth', ssr: false }
]

plugins/auth.js

export default ({ store, redirect, route }) => {
	// doesn't work
	redirect('/admin/login')

	// doesn't work
	return new Promise((resolve, reject) => {
		redirect('/admin/login')
		resolve()
	})

	// works, but only the url updates, the page doesn't render
	return new Promise((resolve, reject) => {
		redirect('/admin/login')
	})
})
This question is available on Nuxt.js community (#c1793)