Title: SSR route redirects drop the query string on relative `redirectTo` · Issue #34298 · angular/angular-cli · GitHub
Open Graph Title: SSR route redirects drop the query string on relative `redirectTo` · Issue #34298 · angular/angular-cli
X Title: SSR route redirects drop the query string on relative `redirectTo` · Issue #34298 · angular/angular-cli
Description: CLI tool for Angular. Contribute to angular/angular-cli development by creating an account on GitHub.
Open Graph Description: CLI tool for Angular. Contribute to angular/angular-cli development by creating an account on GitHub.
X Description: CLI tool for Angular. Contribute to angular/angular-cli development by creating an account on GitHub.
Opengraph URL: https://github.com/angular/angular-cli
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"SSR route redirects drop the query string on relative `redirectTo`","articleBody":"### Command\n\nother\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\n_No response_\n\n### Description\n\nWhen a request matches a route with a string `redirectTo`, `@angular/ssr` answers with a 302 built from the route config, without running the router. For a **relative** `redirectTo`, the query string of the request is dropped.\n\nThe Angular router keeps it: a relative redirect only rewrites the matched segments and continues with the rest of the URL. So `/search?q=x` with `{ path: '', redirectTo: 'results' }` under `search` ends up at `/search/results?q=x` with in-app navigation, but at `/search/results` on a full page load (direct link, reload, link from an email).\n\nFor absolute redirects the router drops the query as well, so these already agree.\n\n### Minimal Reproduction\n\n```sh\nnpx @angular/cli@22.2.2 new repro-app --ssr --defaults\ncd repro-app\n```\n\n`src/app/app.routes.ts`:\n\n```ts\nimport { Component } from '@angular/core';\nimport { Routes } from '@angular/router';\n\n@Component({ template: 'Results page' })\nclass Results {}\n\nexport const routes: Routes = [\n {\n path: 'search',\n children: [\n { path: '', redirectTo: 'results', pathMatch: 'full' },\n { path: 'results', component: Results },\n ],\n },\n];\n```\n\n`src/app/app.routes.server.ts` (server rendering, so the request reaches the redirect handling instead of a prerendered redirect page):\n\n```ts\nimport { RenderMode, ServerRoute } from '@angular/ssr';\n\nexport const serverRoutes: ServerRoute[] = [{ path: '**', renderMode: RenderMode.Server }];\n```\n\n```sh\nnpx ng build\nNG_ALLOWED_HOSTS=localhost PORT=4000 node dist/repro-app/server/server.mjs\ncurl -si 'localhost:4000/search?q=x' | grep -i '^location'\n```\n\nExpected: `location: /search/results?q=x` (where the router navigates). Actual: `location: /search/results`.\n\n### Exception or Error\n\n```text\n$ curl -si 'localhost:4000/search?q=x' | head -3\nHTTP/1.1 302 Found\nX-Powered-By: Express\nlocation: /search/results\n```\n\n### Your Environment\n\n```text\n _ _ ____ _ ___\n / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|\n / △ \\ | '_ \\ / _` | | | | |/ _` | '__| | | | | | |\n / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |\n /_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|\n |___/\n\n\nAngular CLI : 22.2.2\nAngular : 22.2.2\nNode.js : 24.18.0\nPackage Manager : npm 11.16.0\nOperating System : linux x64\n\n┌───────────────────────────┬───────────────────┬───────────────────┐\n│ Package │ Installed Version │ Requested Version │\n├───────────────────────────┼───────────────────┼───────────────────┤\n│ @angular/build │ 22.2.2 │ ^22.2.2 │\n│ @angular/cli │ 22.2.2 │ ^22.2.2 │\n│ @angular/common │ 22.2.2 │ ^22.2.0 │\n│ @angular/compiler │ 22.2.2 │ ^22.2.0 │\n│ @angular/compiler-cli │ 22.2.2 │ ^22.2.0 │\n│ @angular/core │ 22.2.2 │ ^22.2.0 │\n│ @angular/forms │ 22.2.2 │ ^22.2.0 │\n│ @angular/platform-browser │ 22.2.2 │ ^22.2.0 │\n│ @angular/platform-server │ 22.2.2 │ ^22.2.0 │\n│ @angular/router │ 22.2.2 │ ^22.2.0 │\n│ @angular/ssr │ 22.2.2 │ ^22.2.2 │\n│ rxjs │ 7.8.2 │ ~7.8.0 │\n│ typescript │ 6.0.3 │ ~6.0.2 │\n└───────────────────────────┴───────────────────┴───────────────────┘\n```\n\n### Anything else relevant?\n\n[`app.ts#L168-L176`](https://github.com/angular/angular-cli/blob/6ecbadaba2c3b3493b67d10b7757d8974bf9b8a1/packages/angular/ssr/src/app.ts#L168-L176) builds `Location` from the stored `redirectTo` and never uses `url.search`. By then `redirectTo` has already been resolved to an absolute path, so whether it was relative is no longer known.\n\nRouter side: for a relative redirect, `recognize.ts` keeps only the segments of the new tree and continues with the original URL tree, so the query is kept. An absolute redirect throws `AbsoluteRedirect(newTree)`, whose query comes from `redirectTo` only. Render-time redirects (guards, `router.navigate`) already keep the query (#31883).\n\nI have a fix with tests and will open a PR for it.\n\nNot browser specific. Seen with the default Express `server.ts` generated by `ng new --ssr`; the redirect comes from `AngularNodeAppEngine.handle()`, not from Express itself.\n","author":{"url":"https://github.com/bschaeublin","@type":"Person","name":"bschaeublin"},"datePublished":"2026-10-09T21:26:18Z","url":"https://github.com/angular/angular-cli/issues/34298"}
| 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 | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:a87c74ff-d1fd-49f6-7113-f0537c931b20 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9FA0:38E7B3:17D456:20FDB8:6AFDD9F7 |
| html-safe-nonce | 42516d4b29f97e94a46e18da287af712621cca8d767604dbb45741e0e9eb4676 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkEwOjM4RTdCMzoxN0Q0NTY6MjBGREI4OjZBRkREOUY3IiwidmlzaXRvcl9pZCI6IjQ1NDExNDUwNzM2MjU5NzkzODMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 96b1a754cb522acd889e0e8ba65cf6f40b1841d1b710450062e262ec4a75a514 |
| hovercard-subject-tag | repository:36891867 |
| 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/angular/angular-cli/issues/34298 |
| twitter:image | https://repository-images.githubusercontent.com/36891867/7600907d-5c07-47a5-a7b5-80b9c8922d6c |
| twitter:card | summary_large_image |
| og:image | https://repository-images.githubusercontent.com/36891867/7600907d-5c07-47a5-a7b5-80b9c8922d6c |
| og:image:alt | CLI tool for Angular. Contribute to angular/angular-cli development by creating an account on GitHub. |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9918bd4004419458bcd838065ac2a76b76ebd11705d73909fff5ab99e996fa23 |
| turbo-cache-control | no-cache |
| 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 | a231c174493a6a442c0b0544475c918b30128208 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width