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

Router.Navigate ignoring canDeactivate Failures #422

Open

Description

@akasapu2985

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();
    }));

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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