Skip to content

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

Open
alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:fix-schematic-guard-urlsegment
Open

fix(@schematics/angular): import UrlSegment instead of subPath in guard generator#33807
alan-agius4 wants to merge 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer 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.

1 participant