@@ -13,7 +13,7 @@ module.exports = {
1313 // 1. return a boolean
1414 // 2. return a promise that resolves to a boolean
1515 // 3. explicitly call transition.next() or abort()
16- canActivate : function (transition ) {
16+ canActivate (transition ) {
1717 console .log (' inbox canActivate?' )
1818 if (transition .from .path === ' /about' ) {
1919 alert (' cannot navigate from /about to /inbox' )
@@ -25,23 +25,32 @@ module.exports = {
2525 },
2626
2727 // same deal with beforeActicate
28- canDeactivate : function (transition ) {
28+ canDeactivate (transition ) {
2929 return confirm (' Are you sure you want to leave inbox?' )
3030 },
3131
32- activate : function (transition ) {
32+ // activate hook is called when the route is matched
33+ // and the component has been created.
34+ // this hook controls the timing of the component
35+ // switching - the switching won't start until this
36+ // hook is resolved.
37+ activate () {
3338 console .log (' activating inbox...' )
34- transition .next ()
39+ return new Promise ((resolve ) => {
40+ console .log (' inbox activated.' )
41+ resolve ()
42+ })
3543 },
3644
3745 // for doing cleanups
38- deactivate : function (transition ) {
39- console .log (' inbox deactivate' )
40- transition .next ()
46+ // destructuring can make hooks cleaner
47+ deactivate ({ next }) {
48+ console .log (' inbox deactivated.' )
49+ next ()
4150 }
4251 },
4352
44- data : function () {
53+ data () {
4554 return {
4655 message: {}
4756 }
0 commit comments