angular/angular-cli · warning

Location header "${resHeaders.get('location')}" will be igno

Error message

Location header "${resHeaders.get('location')}" will be ignored and set to "${location}".

What it means

`createRedirectResponse` builds a redirect with a computed `location` (e.g. from Accept-Language negotiation). If the caller-supplied headers already contain a `location` header, it would be overwritten, so in dev mode (`ngDevMode`) the engine warns that the original Location value is ignored and replaced.

Source

Thrown at packages/angular/ssr/src/utils/redirect.ts:50

 * @param headers - Additional headers to include in the response.
 * @returns A `Response` object representing the HTTP redirect.
 */
export function createRedirectResponse(
  location: string,
  status = 302,
  headers?: Record<string, string> | Headers,
): Response {
  if (ngDevMode && !isValidRedirectResponseCode(status)) {
    throw new Error(
      `Invalid redirect status code: ${status}. ` +
        `Please use one of the following redirect response codes: ${[...VALID_REDIRECT_RESPONSE_CODES.values()].join(', ')}.`,
    );
  }

  const resHeaders = headers instanceof Headers ? headers : new Headers(headers);
  if (ngDevMode && resHeaders.has('location')) {
    // eslint-disable-next-line no-console
    console.warn(
      `Location header "${resHeaders.get('location')}" will be ignored and set to "${location}".`,
    );
  }

  // Ensure unique values for Vary header
  const varyArray = resHeaders.get('Vary')?.split(',') ?? [];
  const varySet = new Set(['X-Forwarded-Prefix']);
  for (const vary of varyArray) {
    const value = vary.trim();

    if (value) {
      varySet.add(value);
    }
  }

  resHeaders.set('Vary', [...varySet].join(', '));
  resHeaders.set('Location', location);

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Remove the `location` entry from the headers you pass to `createRedirectResponse` and let the function compute it.
  2. If you need a custom target, use the API's dedicated location/target parameter instead of pre-setting the header.
  3. Silence in production is automatic (ngDevMode only), but fix the duplicate for correctness regardless.

Example fix

// before
const headers = new Headers({ location: '/custom' });
createRedirectResponse(request, headers, 302);
// after
const headers = new Headers();
createRedirectResponse(request, headers, 302); // location computed by the API
Defensive patterns

Strategy: validation

Validate before calling

// ensure no pre-set location header before creating a redirect
const h = headers instanceof Headers ? headers : new Headers(headers);
if (h.has('location')) throw new Error('Strip location header; createRedirectResponse sets it.');

Prevention

When it happens

Trigger: Calling `createRedirectResponse` (directly or via `redirectBasedOnAcceptLanguage`, interceptors/handlers that produce redirect responses) with a `Headers` object that already has `location` set while `ngDevMode` is true.

Common situations: Manually adding a Location header in a server interceptor and also using locale-based redirects; middleware setting redirects that conflict with the framework's computed redirect target.

Related errors


AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30). Data as JSON: /api/errors/6fa7d809f1d34e74. Report an issue: GitHub.