durandaldurandal-navigation

Is it possible to detect if the user can go back?


Basically, I need to replicate the browser back button on my app (I do not want it, but I need to do it :/)

On durandal, I can navigate back by calling router.navigateBack();. But there is not always a page back (the browser back button get disabled when there is not). So, it is possible to detect if there is a previous page?

I am thinking in creating a simple counter that increments when the user navigate and decrement when it clicks on my "back" button, but I do not now how can I detect the user clicked the browser back button. If there is some way to know that there is not any previous page, it would be nice.


Solution

  • I was able to do this by intercepting the router.on('router:route:activating') event. When the user navigate, I increment a variable, when he goes back (router.navigatingBack will be true even if he clicked on the browser back button!) I decrement it. When it is 0, I disable the go back button.