Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

docs(guide/Component Router): describe your change... #14237

Closed
wants to merge 1 commit into from

Conversation

Josh68
Copy link
Contributor

@Josh68 Josh68 commented Mar 14, 2016

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Docs update

What is the current behavior? (You can also link to an open issue here)

Method $routerCanActivate lifecycle hook does not appear to exist for components in 1.x

What is the new behavior (if this is a feature change)?

The $canActivate hook on the CDO appears to be the only way to control route resolution for components in 1.x

Does this PR introduce a breaking change?

No

Please check if the PR fulfills these requirements

Other information:

NOTES:

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.

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.
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

1 similar comment
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@Josh68
Copy link
Contributor Author

Josh68 commented Mar 15, 2016

I have signed the CLA. Thanks,

Josh Schneider

On Mon, Mar 14, 2016 at 2:28 PM, googlebot [email protected] wrote:

Thanks for your pull request. It looks like this may be your first
contribution to a Google open source project. Before we can look at your
pull request, you'll need to sign a Contributor License Agreement (CLA).

[image: 📝] Please visit https://cla.developers.google.com/
https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll

verify. Thanks.


Reply to this email directly or view it on GitHub
#14237 (comment).

@googlebot
Copy link

CLAs look good, thanks!

1 similar comment
@googlebot
Copy link

CLAs look good, thanks!

@petebacondarwin
Copy link
Contributor

While this change is accurate, right now. I actually want to change the hook's name to be $routerCanActivate to keep it consistent with the other hooks.

@petebacondarwin petebacondarwin self-assigned this Mar 16, 2016
@petebacondarwin petebacondarwin added this to the Purgatory milestone Mar 16, 2016
@Josh68
Copy link
Contributor Author

Josh68 commented Mar 16, 2016

I kind of thought that might be the case. As an option, maybe it should be made very clear on the new documentation (like right at the top) what the exact status of ngcomponentrouter is. I'm sure I'm not alone in trying to setup a new 1.5.x project and take advantage of components and the component router, but the router itself seems to be an afterthought to 2.x development. I'm sure the team is ridiculously busy, so if you have any recommendations for other mods to the 1.5.x component router docs, I will put in a different PR. Thanks.

@petebacondarwin
Copy link
Contributor

OK, let's merge this since it is the status quo. There will have to be a breaking change announcement with a rename of the hook anyway

petebacondarwin pushed a commit that referenced this pull request Mar 16, 2016
The hook will most likely be named back to `$routerCanActivate` in the future,
but for now this change is accurate.

Closes #14237
@Josh68
Copy link
Contributor Author

Josh68 commented Mar 16, 2016

Thanks, Pete.

On Wed, Mar 16, 2016 at 9:50 AM, Pete Bacon Darwin <[email protected]

wrote:

Closed #14237 #14237 via
208b84b
208b84b
.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#14237 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants