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

'this$1' undefined in confirmTransition when redirect using next('/') in router.beforeEach #3076

Closed
louisliu15 opened this issue Dec 23, 2019 · 1 comment

Comments

@louisliu15
Copy link

@louisliu15 louisliu15 commented Dec 23, 2019

Version: 3.1.3
Problem:
always has an error when replacing route with another path in router.beforeEach(). Sample code is as follow:

router.beforeEach(function (to, from, next) {
  const hasAccess = store.dispatch('oidcStore/oidcCheckAccess', to);
  if (!hasAccess) {
    next({ name: 'unauthorized', replace: true, });
  }
  else {
    next();
  }
});

the error comes from comfirmTransition() starts from vue-router.esm.js line 2115:

var iterator = function (hook, next) {
    if (this$1.pending !== route) {
      return abort()
    }
    try {
      hook(route, current, function (to) {
        if (to === false || isError(to)) {
          // next(false) -> abort navigation, ensure current URL
          this$1.ensureURL(true);
          abort(to);
        } else if (
          typeof to === 'string' ||
          (typeof to === 'object' &&
            (typeof to.path === 'string' || typeof to.name === 'string'))
        ) {
          // next('/') or next({ path: '/' }) -> redirect
          abort();
          if (typeof to === 'object' && to.replace) {
            this$1.replace(to);
          } else {
            this$1.push(to);
          }
        } else {
          // confirm transition and pass on the value
          next(to);
        }
      });
    } catch (e) {
      abort(e);
    }
  };

where the this$1 is always undefined and cause an exception when trying to replace the router with a new one running this$1.replace(to);
I am not pretty sure if this is a common error when doing rerouting in beforeEach(), or a special case when I do the login through OIDC server and return back to the application then. The callback from OIDC looks fine:

created () {
    this.oidcSignInCallback()
      .then((redirectPath) => {
        this.$router.push(redirectPath);
      })
      .catch(err => {
        this.$router.push('/signin-oidc-error'); // Handle errors any way you want
        throw err;
      });
  }
@vue-bot

This comment has been minimized.

Copy link

@vue-bot vue-bot commented Dec 23, 2019

Hello, thank you for taking time filling this issue!

However, we kindly ask you to use our Issue Helper when creating new issues, in order to ensure every issue provides the necessary information for us to investigate. This explains why your issue has been automatically closed by me (your robot friend!).

I hope to see your helper-created issue very soon!

@vue-bot vue-bot closed this Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.