How to access the previous route from Durandal router

968 Views Asked by At

Is there a way to access the previous route/instruction from the Durandal.js router? I know I can do router.navigateBack() to actually navigate back, but I want to know the route that I will navigating back to before I trigger the navigation.

1

There are 1 best solutions below

2
Maleki On BEST ANSWER

Not directly I'm afraid.

router.navigateBack() is defined in router.js as

    router.navigateBack = function() {
        history.navigateBack();
    };

And history.navigateBack() is defined in history.js as

    history.navigateBack = function() {
        history.history.back();
    };

and history.history is an alias defined above for window.history which is part of the browser and would cause security issues if exposed.

If you want to have that functionality you'll have to implement it yourself. Possibly by intercepting router.navigate() and router.navigateBack().