Add functional router guards and resolvers#24170
Conversation
f3c8edf to
1a11ea1
Compare
alan-agius4
left a comment
There was a problem hiding this comment.
I am concerned that this is happing outside of a major version. As there are 2 changes in behaviour here which technically are breaking changes.
I don't know what the CLI team considers breaking, so you'll have to help determine what we're allowed to do here. I assumed, maybe incorrectly, that keeping all the options the same but changing the defaults would be fine. |
4d8e2ed to
4c34666
Compare
77c2a9c to
20b392d
Compare
20b392d to
78482b3
Compare
| "type": "string" | ||
| }, | ||
| "default": ["CanActivate"], | ||
| "x-prompt": "Which interfaces would you like to implement?" |
There was a problem hiding this comment.
I think the prompt in this case should be removed. Since otherwise there wouldn't be a way to use guardType.
There was a problem hiding this comment.
I'm assuming there's not a way to make the prompt conditional? I feel like the lack of a prompt is a step down in UX.
There was a problem hiding this comment.
Correct. we don't support conditional prompts.
There was a problem hiding this comment.
So I tried this out and I don't think this is going to work. The experience now is that ng g guard myGuard will just generate a canActivate guard automatically. Most users will not know about the implements flag and will not know how to generate a guard of another type. We'll have to come up with another way to make this work.
There was a problem hiding this comment.
Okay, I updated the approach to use the --functional flag and throw an error if there is more than 1 value for implements when using it. The names of the existing implements options are the interfaces, and while this isn't ideal, I don't think it's really an issue.
PTAL
45bc058 to
9589adb
Compare
16bf2e3 to
4a6495b
Compare
alan-agius4
left a comment
There was a problem hiding this comment.
LGTM, one little nit.
…outer guards and resolvers Functional guards and resolvers were introduced in the Angular router in v14.2. This commit adds the ability to generate functional router guards by specifying `--guardType` instead of `--implements`. These guards are also accompanied by a test that includes a helper function for executing the guard in the `TestBed` environment so that any `inject` calls in the guard will work properly. Functional resolvers are generated by adding the `--functional` flag.
4a6495b to
1a1dd53
Compare
…ional router guards and resolvers
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Functional guards and resolvers were introduced in the Angular router in v14.2.
This commit adds the ability to generate functional router guards by specifying
--guardTypeinstead of--implements. These guards are also accompanied by a test that includes a helper function for executing the guard in theTestBedenvironment so that anyinjectcalls in the guard will work properly. Functional resolvers are generated by adding the--functionalflag.