Skip to content

Commit c83c411

Browse files
committed
docs(guide/Component Router): describe your change...
From what I can tell, the only way of "resolving" for a component route is in the component's definition object and the method is $canActivate, not $routerCanActivate. Adding a $routerCanActivate alternative would be helpful as a method that can be called on the constructor. I did find a helpful min-safe pattern that might be worth documenting. This is the ability to inject into the CDO's $canActivate method by putting to-be-injected module strings AFTER the default parameters ($nextInstruction and $prevInstruction), followed by the callback with the injected modules as the 3rd - xx arguments. This way I can reference a service to check authentication status (for example), returning a promise that will resolve to true or false and thereby either permit the route to proceed or kill it. However, the best feature would be to add some way to reference a routeProvider, as with ngRoute, for global $canActivate patterns. A pattern I had successfully used with ngRoute was to extend the "when" method to do my authentication check and abort any route that had a configuration setting like "requiresAuth." To be able to do the same with component-based routes would be helpful, but I haven't figured out how. Thanks.
1 parent a4e60cb commit c83c411

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

docs/content/guide/component-router.ngdoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -956,17 +956,17 @@ respectively.
956956

957957
**How do I prevent navigation from occurring?**
958958

959-
Each **Component** can provide the `$routerCanActivate` and `$routerCanDeactivate` **Lifecycle Hooks**. The
960-
`$routerCanDeactivate` hook is an instance method on the **Component**. The `$routerCanActivate` hook is a
961-
static method defined on either the **Component Definition Object** or the **Component's** constructor function.
959+
Each **Component** can provide the `$canActivate` and `$routerCanDeactivate` **Lifecycle Hooks**. The
960+
`$routerCanDeactivate` hook is an instance method on the **Component**. The `$canActivate` hook is used as a
961+
static method defined on the **Component Definition Object**.
962962

963963
The **Router** will call these hooks to control navigation from one **Route** to another. Each of these hooks can
964964
return a `boolean` or a Promise that will resolve to a `boolean`.
965965

966966
During a navigation, some **Components** will become inactive and some will become active. Before the navigation
967967
can complete, all the **Components** must agree that they can be deactivated or activated, respectively.
968968

969-
The **Router** will call the `$routerCanDeactivate` and `$routerCanActivate` hooks, if they are provided. If any
969+
The **Router** will call the `$routerCanDeactivate` and `$canActivate` hooks, if they are provided. If any
970970
of the hooks resolve to `false` then the navigation is cancelled.
971971

972972
### Dialog Box Service

0 commit comments

Comments
 (0)