Title: ssr: string redirectTo drops trailing slash in query and fragment · Issue #34511 · angular/angular-cli · GitHub
Open Graph Title: ssr: string redirectTo drops trailing slash in query and fragment · Issue #34511 · angular/angular-cli
X Title: ssr: string redirectTo drops trailing slash in query and fragment · Issue #34511 · angular/angular-cli
Description: Command build, serve Is this a regression? Yes, this behavior used to work in the previous version The previous version in which this bug was not present was none, same baseHref join is there since 19.0.0 Description String redirectTo lo...
Open Graph Description: Command build, serve Is this a regression? Yes, this behavior used to work in the previous version The previous version in which this bug was not present was none, same baseHref join is there since...
X Description: Command build, serve Is this a regression? Yes, this behavior used to work in the previous version The previous version in which this bug was not present was none, same baseHref join is there since...
Opengraph URL: https://github.com/angular/angular-cli/issues/34511
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ssr: string redirectTo drops trailing slash in query and fragment","articleBody":"### Command\n\nbuild, serve\n\n### Is this a regression?\n\n- [ ] Yes, this behavior used to work in the previous version\n\n### The previous version in which this bug was not present was\n\nnone, same baseHref join is there since 19.0.0\n\n### Description\n\nString `redirectTo` loses trailing `/` of query or fragment in `Location`: `'/login?next=/a/'` gives `/login?next=/a` and `'/login#section/'` gives `/login#section`. Same with `X-Forwarded-Prefix` and with base href `/base/`, on 22.2.4 and on main snapshot `22.3.0-next.3+sha-928169a`\n\nFunction redirect with same target keeps it (`/login?next=%2Fa%2F` and `/login#section/`) since router serializes it, so same target gives diffrent `Location` depending only on how redirect is written\n\n### Minimal Reproduction\n\n1. `npx -p @angular/cli@latest ng new repro --ssr --defaults --skip-git`\n2. `src/app/app.routes.ts`:\n\n```ts\nimport { Component } from '@angular/core';\nimport { Routes } from '@angular/router';\n\n@Component({ template: 'login' })\nclass Login {}\n\nexport const routes: Routes = [\n { path: 'login', component: Login },\n { path: 'old', redirectTo: '/login?next=/a/' },\n { path: 'old-hash', redirectTo: '/login#section/' },\n { path: 'old-fn', redirectTo: () => '/login?next=/a/' },\n { path: 'old-fn-hash', redirectTo: () => '/login#section/' },\n];\n```\n\n3. `src/app/app.routes.server.ts`: `[{ path: '**', renderMode: RenderMode.Server }]` so function redirects go through render\n4. `ng build` then `NG_ALLOWED_HOSTS=localhost NG_TRUST_PROXY_HEADERS=x-forwarded-prefix node dist/repro/server/server.mjs`\n5. curl:\n\n```text\n$ curl -si localhost:4000/old | grep -i '^location'\nlocation: /login?next=/a\n$ curl -si localhost:4000/old-hash | grep -i '^location'\nlocation: /login#section\n$ curl -si localhost:4000/old-fn | grep -i '^location'\nlocation: /login?next=%2Fa%2F\n$ curl -si localhost:4000/old-fn-hash | grep -i '^location'\nlocation: /login#section/\n$ curl -si -H 'X-Forwarded-Prefix: /app' localhost:4000/old | grep -i '^location'\nlocation: /app/login?next=/a\n$ curl -si -H 'X-Forwarded-Prefix: /app' localhost:4000/old-hash | grep -i '^location'\nlocation: /app/login#section\n```\n\nWith `ng build --base-href /base/` it's `/base/login?next=/a` and `/base/login#section`. Slash is gone already at build time, `dist/repro/server/angular-app-manifest.mjs` has `\"redirectTo\": \"/login?next=/a\"`\n\nExpected: `/login?next=/a/` and `/login#section/`, with `/app` or `/base` in front when set\n\nActual: trailing slash of query and fragment is gone\n\n### Exception or Error\n\n```text\nnone, only Location header is wrong\n```\n\n### Your Environment\n\n```text\nAngular CLI : 22.2.4\nAngular : 22.2.3\nNode.js : 24.16.0\nPackage Manager : npm 11.13.0\nOperating System : darwin arm64\n\n┌───────────────────────────┬───────────────────┬───────────────────┐\n│ Package │ Installed Version │ Requested Version │\n├───────────────────────────┼───────────────────┼───────────────────┤\n│ @angular/build │ 22.2.4 │ ^22.2.4 │\n│ @angular/cli │ 22.2.4 │ ^22.2.4 │\n│ @angular/common │ 22.2.3 │ ^22.2.0 │\n│ @angular/compiler │ 22.2.3 │ ^22.2.0 │\n│ @angular/compiler-cli │ 22.2.3 │ ^22.2.0 │\n│ @angular/core │ 22.2.3 │ ^22.2.0 │\n│ @angular/forms │ 22.2.3 │ ^22.2.0 │\n│ @angular/platform-browser │ 22.2.3 │ ^22.2.0 │\n│ @angular/platform-server │ 22.2.3 │ ^22.2.0 │\n│ @angular/router │ 22.2.3 │ ^22.2.0 │\n│ @angular/ssr │ 22.2.4 │ ^22.2.4 │\n│ rxjs │ 7.8.2 │ ~7.8.0 │\n│ typescript │ 6.0.3 │ ~6.0.2 │\n│ vitest │ 5.0.5 │ ^5.0.0 │\n└───────────────────────────┴───────────────────┴───────────────────┘\n\nsame output with @angular/ssr 22.3.0-next.3+sha-928169a from angular-ssr-builds\n```\n\n### Anything else relevant?\n\n`joinUrlParts` trims trailing `/` of every part, and two places still pass it whole target with query and fragment: [`joinUrlParts(baseHref, metadata.redirectTo)`](https://github.com/angular/angular-cli/blob/928169a68b522b8f38334ee2626687704495e5ec/packages/angular/ssr/src/routes/ng-routes.ts#L900) in `extractRoutesAndCreateRouteTree` and [prefix join](https://github.com/angular/angular-cli/blob/928169a68b522b8f38334ee2626687704495e5ec/packages/angular/ssr/src/app.ts#L170-L173) in `AngularServerApp.handle`\n\n[#34467](https://github.com/angular/angular-cli/pull/34467) description says `joinUrlParts` is applied only to path portion when prepending `baseHref` or `X-Forwarded-Prefix` so trailing slashes in query or fragment are preserved, but both joins above still take whole target. If that's not intended I can send PR that splits off query and fragment first, like `resolveRedirectTo` does\n","author":{"url":"https://github.com/thekhegay","@type":"Person","name":"thekhegay"},"datePublished":"2026-10-23T16:19:26Z","url":"https://github.com/angular/angular-cli/issues/34511"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:27d03aa8-a7b0-766a-2fa0-114791e65137 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8220:236B3F:A9C3DA:EE9094:6AFDCEE7 |
| html-safe-nonce | 034321f47430c65b1d7246c131eff240ddf0b5f6c56f554f18d69ccea2f4f48a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjIwOjIzNkIzRjpBOUMzREE6RUU5MDk0OjZBRkRDRUU3IiwidmlzaXRvcl9pZCI6Ijg4NzY0NDk3NjYxNjcxMzgwMjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | afe356a6ec10c2f6b4586d2293f7d88203ac1ca61a3bcba06b524ddba733bac1 |
| hovercard-subject-tag | issue:6001436534 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/34511/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4e8172cb90799c8c5818cbf7818ac37a536a0fbb57b66fbe5f065aa167b11556/angular/angular-cli/issues/34511 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4e8172cb90799c8c5818cbf7818ac37a536a0fbb57b66fbe5f065aa167b11556/angular/angular-cli/issues/34511 |
| og:image:alt | Command build, serve Is this a regression? Yes, this behavior used to work in the previous version The previous version in which this bug was not present was none, same baseHref join is there since... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | thekhegay |
| hostname | github.com |
| expected-hostname | github.com |
| None | 26886a40b582b821a7a76351e0a2f42b6d6160854b6e2520db24f31fd7be5da7 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 68ebaa631a1d248d69ebde4b9c5defd3a19aeb2f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width