Skip to content

fix(@schematics/angular): import UrlSegment instead of subPath in guard generator - #33807

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:fix-schematic-guard-urlsegment
Aug 10, 2026
Merged

fix(@schematics/angular): import UrlSegment instead of subPath in guard generator#33807
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:fix-schematic-guard-urlsegment

Conversation

@alan-agius4

@alan-agius4 alan-agius4 commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

When generating class-based CanMatch guards (ng g guard --implements=CanMatch --no-functional), the guard implementation template defines canMatch(route: Route, segments: UrlSegment[]).

Previously, the schematic added 'subPath' instead of 'UrlSegment' to @angular/router named imports. Because @angular/router does not export subPath, this generated code with broken imports (Module '"@angular/router"' has no exported member 'subPath') while leaving UrlSegment unimported (Cannot find name 'UrlSegment').

This change ensures UrlSegment is imported when generating CanMatch guards.

@alan-agius4
alan-agius4 requested a review from clydin August 7, 2026 15:26
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Aug 7, 2026
@alan-agius4
alan-agius4 marked this pull request as ready for review August 7, 2026 15:26

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Angular guard schematic to import UrlSegment instead of subPath when generating a guard that implements CanMatch. The corresponding unit tests have also been updated to reflect this change. There are no review comments, and I have no additional feedback to provide.

…rd generator

When generating class-based `CanMatch` guards (`ng g guard --implements=CanMatch --no-functional`), the guard implementation template defines `canMatch(route: Route, segments: UrlSegment[])`.

Previously, the schematic added `'subPath'` instead of `'UrlSegment'` to `@angular/router` named imports. Because `@angular/router` does not export `subPath`, this generated code with broken imports (`Module '"@angular/router"' has no exported member 'subPath'`) while leaving `UrlSegment` unimported (`Cannot find name 'UrlSegment'`).

This change ensures `UrlSegment` is imported when generating `CanMatch` guards.
@alan-agius4
alan-agius4 force-pushed the fix-schematic-guard-urlsegment branch from 60bd0e5 to ec25af5 Compare August 7, 2026 15:27
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 10, 2026
@alan-agius4
alan-agius4 merged commit c536ae3 into angular:main Aug 10, 2026
40 checks passed
@alan-agius4
alan-agius4 deleted the fix-schematic-guard-urlsegment branch August 10, 2026 15:53
@alan-agius4

Copy link
Copy Markdown
Collaborator Author

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @schematics/angular target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants