Skip to content

Select Close to throw a redirect error #3260

Closed
@tangdaohai

Description

@tangdaohai

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions