# Checking for canDeactivate before navigateToRoute

**URL:** <https://discourse.aurelia.io/t/checking-for-candeactivate-before-navigatetoroute/51>\
**Category:** Help Requests\
**Created:** [October 23, 2017, 11:34am UTC](https://discourse.aurelia.io/t/checking-for-candeactivate-before-navigatetoroute/51 "2017-10-23T11:34:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aynurin](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/aynurin/32/42_2.png) [@aynurin](https://discourse.aurelia.io/u/aynurin)\
**Post date:** [October 23, 2017, 11:34am UTC](https://discourse.aurelia.io/t/checking-for-candeactivate-before-navigatetoroute/51/1 "2017-10-23T11:34:02Z")

</div>

Hi there,

I’m a beginner so bear with me if this is a silly question.

I have a VM ‘foo’ with canDeactivate implementation that is hardcoded to return `false`. In another VM called ‘bar’ I call `navigateToRoute('baz')`, and the behavior is as expected: the displayed view is still ‘foo’. But in the scope of ‘bar’ I don’t know what actually has happened.

When calling the `navigateToRoute('baz')`, how do I know if the navigation did not succeed?

Thanks for any help!

---

<div class="post-metadata">

**Author:** ![mttmccb](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/mttmccb/32/38_2.png) [@mttmccb](https://discourse.aurelia.io/u/mttmccb)\
**Post date:** [October 23, 2017, 12:09pm UTC](https://discourse.aurelia.io/t/checking-for-candeactivate-before-navigatetoroute/51/2 "2017-10-23T12:09:48Z")

</div>

It looks like it navigateToRoute returns a promise so you can check that happened as expected.

I put together [an example gist.run](https://gist.run/?id=58589efed415a6cf3046b6d5d178b2c9)

---

<div class="post-metadata">

**Author:** ![aynurin](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/aynurin/32/42_2.png) [@aynurin](https://discourse.aurelia.io/u/aynurin)\
**Post date:** [October 23, 2017, 12:33pm UTC](https://discourse.aurelia.io/t/checking-for-candeactivate-before-navigatetoroute/51/3 "2017-10-23T12:33:07Z")

</div>

> [@mttmccb](#):
>
> navigateToRoute returns a promise

I see, that’s interesting. I’m using TypeScript, and the editor tells me that navigateToRoute returns a boolean. Now that I tried it with an `await` I can see that this is an object that looks like the following in case of successful navigation:

```
{
	"completed": true,
	"output": undefined,
	"status": "completed"
}

```

and in case of failure (e.g. canDeactivate = false) it looks like this:

```
{
	"completed": false,
	"output": false,
	"status": "canceled"
}	

```

I’ve replaced NOPE with `${navigationFailed.completed}` in your gist to confirm that.

So I could make it work, but obviously my VS Code is not happy that I’m checking for `nav.completed === true` given that it thinks that `nav` is a `boolean`. Probably I need to update something…

Anyway, the root problem is resolved, thank you for your help!

---

<div class="post-metadata">

**Author:** ![mttmccb](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/mttmccb/32/38_2.png) [@mttmccb](https://discourse.aurelia.io/u/mttmccb)\
**Post date:** [October 23, 2017, 1:02pm UTC](https://discourse.aurelia.io/t/checking-for-candeactivate-before-navigatetoroute/51/4 "2017-10-23T13:02:45Z")

</div>

hmm you’re right about the definition, I don’t know if the docs/typings just need updated? You might be able to extend the interface to replace it but that seems a bit wrong in the long term.

---

<div class="post-metadata">

**Author:** ![ashley](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/ashley/32/12_2.png) [@ashley](https://discourse.aurelia.io/u/ashley)\
**Post date:** [October 23, 2017, 5:46pm UTC](https://discourse.aurelia.io/t/checking-for-candeactivate-before-navigatetoroute/51/5 "2017-10-23T17:46:39Z")

</div>

I’d say updating the type definition wouldn’t be too big of a deal. I’ve created a pull request for it: [https://github.com/aurelia/router/pull/544](https://github.com/aurelia/router/pull/544)
