Question

My question is quite simple and needs no special explanation.

In Durandal, is it possible to control whether or not to use transition when switching from/to a viewmodel?

The reason why I want to be able to deactivate the animation is as follows:

I have a search form module quicksearch.js in my shell/masterpage that is accessible from anywhere. What it does is validate the input and then simply redirect to the results page results.js passing the search parameters in an URL after hash. The results.js takes care of querying the server.

When the quicksearch.js module is used while on a page other than results.js, the animation is triggered and it's desired behavior. However, when on results.js and using quicksearch.js, the only thing that changes in URL is the parameter string (module name right after the hash is left unchanged). Still, this goes through all the lifecycle of activating results.js again, with animating from results.js to results.js and that looks pretty bad.

So, is there any way to, under a condition, prevent Durandal from animating the content and just compose and bind the view?

Was it helpful?

Solution

I haven't found a way to control the transition process from my viewmodel, I doubt there is a way to do it.

Yet, the reason I asked was that I wanted to prevent Durandal from animating when navigating to the current page with different hash query string (changing this query string does trigger the navigation). The solution was to create a custom transition and to check whether the target view id is or isn't the same as the current view id. rely relied on

context.activeView.dataset.view === context.child.dataset.view;

where context.activeView is the currently attached view and context.child is the view that is about to be bound. Then, if these ids are different, I trigger the animation and if not, I simply hide context.activeView and show the other.

That's it for this case

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top