SSR route redirects drop the query string on relative `redirectTo`
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- express, nodejs, typescript
Línea de trabajo
Start in packages/angular/ssr/src/app.ts around lines 168-176, where the 302 Location is built from the stored redirectTo and url.search is never read. The reporter notes that redirectTo is already absolute by then, so the code must keep track of whether the redirect was relative, and the router's recognize.ts keeps the original query for relative redirects. Done means the relative case returns the query in Location, the absolute case is unchanged, and the curl command from the report shows /search/results?q=x.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Command
other
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
No response
Description
When 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.
The 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).
For absolute redirects the router drops the query as well, so these already agree.
Minimal Reproduction
npx @angular/[email protected] new repro-app --ssr --defaults
cd repro-app
src/app/app.routes.ts:
import { Component } from '@angular/core';
import { Routes } from '@angular/router';
@Component({ template: 'Results page' })
class Results {}
export const routes: Routes = [
{
path: 'search',
children: [
{ path: '', redirectTo: 'results', pathMatch: 'full' },
{ path: 'results', component: Results },
],
},
];
src/app/app.routes.server.ts (server rendering, so the request reaches the redirect handling instead of a prerendered redirect page):
import { RenderMode, ServerRoute } from '@angular/ssr';
export const serverRoutes: ServerRoute[] = [{ path: '**', renderMode: RenderMode.Server }];
npx ng build
NG_ALLOWED_HOSTS=localhost PORT=4000 node dist/repro-app/server/server.mjs
curl -si 'localhost:4000/search?q=x' | grep -i '^location'
Expected: location: /search/results?q=x (where the router navigates). Actual: location: /search/results.
Exception or Error
$ curl -si 'localhost:4000/search?q=x' | head -3
HTTP/1.1 302 Found
X-Powered-By: Express
location: /search/results
Your Environment
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI : 22.2.2
Angular : 22.2.2
Node.js : 24.18.0
Package Manager : npm 11.16.0
Operating System : linux x64
┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build │ 22.2.2 │ ^22.2.2 │
│ @angular/cli │ 22.2.2 │ ^22.2.2 │
│ @angular/common │ 22.2.2 │ ^22.2.0 │
│ @angular/compiler │ 22.2.2 │ ^22.2.0 │
│ @angular/compiler-cli │ 22.2.2 │ ^22.2.0 │
│ @angular/core │ 22.2.2 │ ^22.2.0 │
│ @angular/forms │ 22.2.2 │ ^22.2.0 │
│ @angular/platform-browser │ 22.2.2 │ ^22.2.0 │
│ @angular/platform-server │ 22.2.2 │ ^22.2.0 │
│ @angular/router │ 22.2.2 │ ^22.2.0 │
│ @angular/ssr │ 22.2.2 │ ^22.2.2 │
│ rxjs │ 7.8.2 │ ~7.8.0 │
│ typescript │ 6.0.3 │ ~6.0.2 │
└───────────────────────────┴───────────────────┴───────────────────┘
Anything else relevant?
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.
Router 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).
I have a fix with tests and will open a PR for it.
Not browser specific. Seen with the default Express server.ts generated by ng new --ssr; the redirect comes from AngularNodeAppEngine.handle(), not from Express itself.
- Lenguaje dominante
- TypeScript
- Estrellas
- 27k
- Forks
- 11.8k
- Merge medio
- 1 d 32 min
- PR fusionados (30 d)
- 138
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de angular/angular-cli
-
area: @angular/cli
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
angular/angular-cli#34307 ·
Los mantenedores suelen responder en 1 día
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-serverAbiertoarea: @angular/build gemini-triaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
angular/angular-cli#33955 ·
Los mantenedores suelen responder en 1 día
-
area: @angular/cli gemini-triaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
angular/angular-cli#33055 · 1 comentario · 3 reacciones ·
Los mantenedores suelen responder en 1 día
-
SSR resolves relative `redirectTo` against the wrong base when the route path has several segmentsPosiblemente ocupada @bschaeublin la tomó hace 2 días. Abiertoarea: @angular/ssr
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
angular/angular-cli#34300 ·
Los mantenedores suelen responder en 1 día
-
area: @angular/build
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
angular/angular-cli#34292 ·
Los mantenedores suelen responder en 1 día
Todos los issues de angular/angular-cli
Issues similares
-
area:tui enhancement platform:macos
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
anthropics/claude-code#101490 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
netlify/netlify-mcp#75 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
atlassian-labs/compiled#1960 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
pnp/cli-microsoft365#7639 ·
Los mantenedores suelen responder en 2 días
-
nextjs-tracking
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
cloudflare/vinext#3887 ·
Los mantenedores suelen responder en 1 día