-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(router): Produce error message when canActivate is used with… #40067
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we include a test?
… redirectTo Redirects in the router are processed before activations. This means that a canActivate will never execute if a route has a redirect. Rather than silently ignoring the invalid config, developers should be notified so they know why it doesn't work. Closes angular#18605 The feature request for a function/class redirect is covered in angular#13373.
Good call - done. |
7b91838
to
8a03bde
Compare
Initial presubmit show at least two problematic configs in the subset of tests run. |
`Route` configs with `redirectTo` as well as `canActivate` are not valid because the `canActivate` guards will never execute. Redirects are applied before activation. There is no error currently for these configs, but another commit will change this so that an error does appear in dev mode. This migration fixes the configs by removing the `canActivate` property.
@mhevery - There were 5 places globally in g3 where this produced new errors. Again, these errors would only happen in dev mode. Still, I've updated the label to target a I've also added a commit that includes a migration for this change. @crisbeto - would you mind reviewing the schematic change? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM on the migration code with a few nits.
packages/core/schematics/migrations/can-activate-with-redirect-to/index.ts
Outdated
Show resolved
Hide resolved
packages/core/schematics/migrations/can-activate-with-redirect-to/util.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for router (not familiar with schematics)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Reviewed-for: dev-infra
`Route` configs with `redirectTo` as well as `canActivate` are not valid because the `canActivate` guards will never execute. Redirects are applied before activation. There is no error currently for these configs, but another commit will change this so that an error does appear in dev mode. This migration fixes the configs by removing the `canActivate` property. PR Close #40067
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. |
… redirectTo
Redirects in the router are processed before activations. This means that a canActivate will
never execute if a route has a redirect. Rather than silently ignoring
the invalid config, developers should be notified so they know why it
doesn't work.
Closes #18605
The feature request for a function/class redirect is covered in #13373.
Note that this is a new error that would prevent routing from working. We may want to discuss the need to land this along with a migration that removes
canActivate
from configs withredirectTo
if this is found to be a common occurrence. Even without a migration, it may still be necessary to land this in a minor/major version to prevent new failures in patch version updates.