Skip to content

Conversation

@alan-agius4
Copy link
Collaborator

This commit addresses an issue where prerendering with i18n and a routesFile could lead to infinite redirect loops or failure to prerender index.html.

The previous urlJoin utility was replaced with more robust URL manipulation functions (joinUrlParts, addTrailingSlash, stripLeadingSlash) to ensure that paths are correctly constructed, especially when dealing with base hrefs and locale subpaths. This ensures that routes from the routesFile are correctly joined with the base href, preventing malformed URLs that cause the redirection issues.

Closes #31877

@alan-agius4 alan-agius4 requested a review from clydin November 20, 2025 08:23
@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 Nov 20, 2025
@alan-agius4 alan-agius4 force-pushed the redirect-loop-ssg branch 3 times, most recently from 1fa347a to 432886b Compare November 20, 2025 09:58
This commit addresses an issue where prerendering with i18n and a `routesFile` could lead to infinite redirect loops or failure to prerender `index.html`.

The previous `urlJoin` utility was replaced with more robust URL manipulation functions (`joinUrlParts`, `addTrailingSlash`, `stripLeadingSlash`) to ensure that paths are correctly constructed, especially when dealing with base hrefs and locale subpaths. This ensures that routes from the `routesFile` are correctly joined with the base href, preventing malformed URLs that cause the redirection issues.

Closes angular#31877
Copy link
Contributor

@hybrist hybrist left a comment

Choose a reason for hiding this comment

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

Is this code subtle enough that it warrants a few test cases?

if (part[0] === '/') {
normalizedPart = normalizedPart.slice(1);
}
if (part[part.length - 1] === '/') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we get to use https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at here since it's been widely available since March 2022?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is copied from the SSR package. I will do a followup to change the .at(-1).

@alan-agius4 alan-agius4 removed the request for review from clydin November 20, 2025 13:54
@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 Nov 20, 2025
@alan-agius4 alan-agius4 merged commit 0fe572e into angular:main Nov 20, 2025
35 checks passed
@alan-agius4 alan-agius4 deleted the redirect-loop-ssg branch November 20, 2025 13:57
@alan-agius4
Copy link
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: @angular/build target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prerendering via "routesFile" with i18n no longer prerenders index.html, produces infinite "Redirecting" loop (since @angular/ssr 20.3.7)

2 participants