refactor(@angular/ssr): combine redirect URL parameter helpers and use DefaultUrlSerializer #34467

Merged
alan-agius4 opened 10:38am on October 21, 2026 wanted to merge 52 Ξ” into angular/angular-cli main from
refactor/ssr-redirect-params

Pull Request Overview

  • Opened on October 21, 2026
  • Status Merged
  • Commit count 2 with first commit October 21, 2026

Total Delta

52 Total Diff Delta

Open Days

Open 18 weekdays

Test Delta

0 Diff Delta in Test Files
Breakdown by Phase

How long has this pull request spent in each phase of its lifecycle?

Fraction of total time Business days Phase
 
0.0 days Authoring 1 commit before pull request opened for review
 
0.0 days Awaiting first review
 
1.7 days Revising work with 1 commit in response to 3 reviews that left 15 comments
 
15.9 days Merge to deploy (still awaiting deployment)

Total time for pull request 1.7 business days from first commit authored to merge
Still awaiting deployment

Author avatar

refactor(@angular/ssr): combine redirect URL parameter helpers and use DefaultUrlSerializer

Follow-up to #34321:
- Combines buildPathWithParams and buildQueryWithParams into buildUrlWithParams.
- Reuses DefaultUrlSerializer from @angular/router for query parameter parsing and serialization instead of custom regex/encoding helpers.
- Adds fast-path checks to avoid regex/splitting and URLSearchParams instantiation when redirect targets do not contain placeholders.
- Applies joinUrlParts only to the path portion of redirect targets when prepending baseHref or X-Forwarded-Prefix so trailing slashes in query parameters or fragments are preserved.

Comments Threads Pending Resolution

gemini-code-assist[bot] reviewed on October 21, 2026
gemini-code-assist[bot] left a comment

## Code Review

This pull request refactors URL and query parameter resolution in the Angular SSR package by consolidating `buildPathWithParams` and `buildQueryWithParams` into a single `buildUrlWithParams` function, and merging `replaceRedirectParams` into `resolveRedirectTo`. Feedback on these changes highlights two potential issues: first, appending `url.search` directly with `+` for relative redirects could result in malformed URLs with multiple `?` characters if the target already contains query parameters; second, resolving path placeholders when `fromPath` has fewer segments than expected could pass `undefined` to `joinUrlParts`, leading to a runtime `TypeError`.

gemini-code-assist[bot] reviewed on October 21, 2026
gemini-code-assist[bot] left a comment

## Code Review

This pull request refactors URL parameter resolution in Angular SSR by replacing buildPathWithParams and buildQueryWithParams with a unified buildUrlWithParams function that leverages Angular's DefaultUrlSerializer. It also optimizes route parameter replacement and prefix handling. Feedback on the changes points out a potential runtime TypeError when resolving path placeholders if a wildcard or positional placeholder refers to an out-of-bounds index, and suggests adding a fallback to 'undefined'.

Resolved Comment Threads

dgp1130 reviewed and approved this work on October 23, 2026
packages/angular/ssr/src/routes/ng-routes.ts
Outdated
178
179
    const parentRoutes = new Map<string, RouteTreeNodeMetadata>();
180
181
    if (typeof redirectTo === 'string') {
182
      let routeSegments: string[] | undefined;
packages/angular/ssr/src/utils/url.ts
Outdated
204
      ...path
205
        .split('/')
206
        .map((part, index) =>
207
          part[0] === '*'
208
            ? (fromPathParts[part.length === 1 ? index : +part.slice(1)] ?? part)
packages/angular/ssr/src/utils/url.ts
Outdated
210
        ),
211
    );
212
  }
213
214
  if (fromSearch !== undefined && suffix[0] === '?' && suffix.includes('=:')) {
gemini-code-assist[bot] reviewed on October 21, 2026
gemini-code-assist[bot] left a comment

## Code Review

This pull request refactors URL and query parameter resolution in the Angular SSR package by consolidating `buildPathWithParams` and `buildQueryWithParams` into a single `buildUrlWithParams` function, and merging `replaceRedirectParams` into `resolveRedirectTo`. Feedback on these changes highlights two potential issues: first, appending `url.search` directly with `+` for relative redirects could result in malformed URLs with multiple `?` characters if the target already contains query parameters; second, resolving path placeholders when `fromPath` has fewer segments than expected could pass `undefined` to `joinUrlParts`, leading to a runtime `TypeError`.

packages/angular/ssr/src/app.ts
Outdated
173
      );
174
175
      // Match Angular router behavior: relative redirects keep the query string.
176
      return createRedirectResponse(
182 177
        relativeRedirect ? location + url.search : 
buildQueryWithParams(
location,
 url.searchParams),