angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Add option to generate a guard for CanDeactivate, CanActivateChild, CanLoad

Open bastienmoulia opened this issue 7 years ago • 3 comments

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [x] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Desired functionality

Actually (7.2.0), when a guard is generated, it implements CanActivate. I would like to see an option to generate a guard with CanDeactivate, CanActivateChild or CanLoad.

bastienmoulia avatar Jan 10 '19 10:01 bastienmoulia

There is a PR for this https://github.com/angular/angular-cli/pull/13109

alan-agius4 avatar Jan 10 '19 11:01 alan-agius4

Just as a note, CanDeactivate was not included in #13100 mainly because in order to implement that properly you need a component class. I have thought about a few ways of doing this but am not sure exactly which way the team would like to go with it. One potential way I see is that if CanDeactivate is selected, then the cli would prompt for a component to implement, and could either create if it doesn't exist or error.

Another more simple approach would be to scaffold the guard with CanDeactivate<> without a component and leave it to the developer to implement, but generating broken code doesn't seem like a great practice to me...

Or I guess it could be generated with any but that also smells a little bit...

Anyway I'd be happy to implement the solution if anyone has thoughts on it? @alan-agius4 @clydin

okeefem2 avatar Jan 10 '19 12:01 okeefem2

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.