Skip to content

Select Close to throw a redirect error #3260

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

Closed
tangdaohai opened this issue Jul 20, 2020 · 2 comments
Closed

Select Close to throw a redirect error #3260

tangdaohai opened this issue Jul 20, 2020 · 2 comments

Comments

@tangdaohai
Copy link

What problem does this feature solve?

when router has redirect I got this error: Redirected when going from "/a" to "/b" via a navigation guard.

I found this line of code(199-200):

} else if (
typeof to === 'string' ||
(typeof to === 'object' &&
(typeof to.path === 'string' || typeof to.name === 'string'))
) {
// next('/') or next({ path: '/' }) -> redirect
abort(createNavigationRedirectedError(current, route))
if (typeof to === 'object' && to.replace) {
this.replace(to)
} else {
this.push(to)
}
} else {
// confirm transition and pass on the value
next(to)
}

Redirection is a commonly used function, I think that this error should not be thrown frequently or provide a function to choose whether to throw an error.

By the way, why should this exception be thrown, and what is its purpose?

I use Google Translate, which may cause difficulty in understanding...

What does the proposed API look like?

// like this
interface NavigationGuardOptions {
  throwError: boolean
}
export type NavigationGuardNext<V extends Vue = Vue> = (
  to?: RawLocation | false | ((vm: V) => any) | void,
  options: NavigationGuardOptions
) => void
@posva
Copy link
Member

posva commented Jul 20, 2020

This has been extensively explained at #2881 (comment) where it explains how to adapt the behavior. There is also an upcoming PR #3220 to add the necessary API to handle this correctly

To make it short, it always was considered an error before, so with Promises, it had to be a rejection (see example using 3.0.0 https://jsfiddle.net/zoh1dj6w/). This is no longer the case in v4, where navigation failures are not promise rejections anymore and a redirection is considered a successful navigation but changing it on v3 would be a breaking change so it only changed on v4

@posva posva closed this as completed Jul 20, 2020
@tangdaohai
Copy link
Author

This has been extensively explained at #2881 (comment)

To make it short, it always was considered an error before, so with Promises, it had to be a rejection (see example using 3.0.0 https://jsfiddle.net/zoh1dj6w/). This is no longer the case in v4, where navigation failures are not promise rejections anymore and a redirection is considered a successful navigation

thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants