KavenG
KavenG

Reputation: 171

How to handle back button after returning a promise from the activate callback in Durandal

We are developing a mobile application using Durandal 2.1

The documentation states that we can return a promise from the activate callback and it should cancel navigation on failure.

We've been trying to use that feature, but it breaks the back button in our application.

As you can see in Durandal's router.js plugin code, the cancelNavigation function is navigating towards the lastUrl:

function cancelNavigation(instance, instruction) {
    system.log('Navigation Cancelled');

    router.activeInstruction(currentInstruction);

    router.navigate(lastUrl, false);

    isProcessing(false);
    rootRouter.explicitNavigation = false;
    rootRouter.navigatingBack = false;
    router.trigger('router:navigation:cancelled', instance, instruction, router);
}

Because of that behavior, using the back button after navigation cancellation will not provide the expected results since it will navigate back to the page that caused the error.

Are we using this feature in the wrong way?

Our goal is to try to load data in the activate function, and then navigate back to the current page if an error occurs.

Any help regarding this woule be greatly appreciated.

Upvotes: 1

Views: 97

Answers (0)

Related Questions