Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Router.Navigate ignoring canDeactivate Failures #422

Open
akasapu2985 opened this issue Jun 15, 2016 · 0 comments
Open

Router.Navigate ignoring canDeactivate Failures #422

akasapu2985 opened this issue Jun 15, 2016 · 0 comments

Comments

@akasapu2985
Copy link

in Router.navigate method, even if the process.then goes to error case, we are not rejecting the promise, and setting the instruction.canonical form. which causes location.path to change, even if the canDeactivate returns false.

Issue: this is causing the navigation to happen twice. And also url changes even if I returned false in canDeactivate.

return this.pipeline.process(instruction).then((function() {
        return $__0._finishNavigating();
      }), (function() {
        return $__0._finishNavigating();
      })).then((function() {
        return instruction.canonicalUrl;
      }));
    },
return nav.call(this, url).then(function (newUrl) {
      if (newUrl) {
        $location.path(newUrl);
      }
    });

when the pipeline.Process fails(canDeactivate returns false), we should finishNavigating but also reject the promise.

my fix for this is

var processDefer = $q.defer();
    this.pipeline.process(instruction).then((function () {
        $__0._finishNavigating();
        instruction.canonicalUrl;
        processDefer.resolve();
    }), (function () {
        $__0._finishNavigating();
        processDefer.reject();
    }));

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

No branches or pull requests

1 participant