Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loader completes prematurely if middleware returns a redirect #2563

Closed
silverbackdan opened this issue Jan 11, 2018 · 6 comments
Closed

Loader completes prematurely if middleware returns a redirect #2563

silverbackdan opened this issue Jan 11, 2018 · 6 comments

Comments

@silverbackdan
Copy link

silverbackdan commented Jan 11, 2018

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)
@clarkdo
Copy link
Member

clarkdo commented Jan 12, 2018

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?

@silverbackdan
Copy link
Author

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.

@Atinux
Copy link
Member

Atinux commented Jan 12, 2018

Hi @silverbackdan

I just pushed a fix about it (e33d502), we will release a new version of Nuxt.js next week.

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

@Atinux Atinux closed this as completed Jan 12, 2018
@silverbackdan
Copy link
Author

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

@Atinux
Copy link
Member

Atinux commented Jan 12, 2018

@silverbackdan I just pushed v1.1.0 :)

@lock
Copy link

lock bot commented Nov 2, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 2, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants