Nuxt.js: Loader completes prematurely if middleware returns a redirect

Created on 11 Jan 2018  路  6Comments  路  Source: nuxt/nuxt.js

It appears that if I return a redirect from router middleware, the loader completes, instead of continuing while the page that is being redirected to loads and that routes middleware are executed.

Please let me know if you'd like a repro. Cheers.

This question is available on Nuxt.js community (#c2228)
question

All 6 comments

It should be a expected behavior in vue-router, if you have nested router.push, the current and to is same route, routing will be ignored.

So if middleware is redirect('/'), when you access '/about', it will execute the middleware twice:

export default function ({ redirect, route }) {
  console.log(route.fullPath)
  redirect('/')
}

Printed two lines: / and /about

If your behavior is not same like above, could you please provide a repo can reproduce the issue?

Thanks for the fast response @clarkdo

I think I may not have explained well or have misunderstood the answer.

The middleware is executed twice, that's all fine. The issue is the loading bar. It stops after the first request and does not start again. So once the middleware calls redirect, the default loading bar finishes instead of starting again for the redirected route.

Hi @silverbackdan

I just pushed a fix about it (https://github.com/nuxt/nuxt.js/commit/e33d5026966e23d71dc33078a9122bf4a9fccd61), we will release a new version of Nuxt.js next week.

It also handle when a redirect is to himself or to another page :)

That's awesome, thanks @Atinux - you rock!

@silverbackdan I just pushed v1.1.0 :)

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattdharmon picture mattdharmon  路  3Comments

nassimbenkirane picture nassimbenkirane  路  3Comments

msudgh picture msudgh  路  3Comments

danieloprado picture danieloprado  路  3Comments

lazycrazy picture lazycrazy  路  3Comments