0

I have a "not found" component:

{
    path: '**',
    loadComponent: () =>
      import('./pages/not-found-page.component').then(
        (c) => c.PageNotFoundComponent,
      ),
}

How can I send the 404 status in the response, so Google doesn't show a soft 404 problem on my app?

1 Answer 1

0

Since Angular version 19, you can easily change the status code only on the server:

export class PageNotFoundComponent {
  private response = inject(RESPONSE_INIT);

  constructor() {
    // Only executes server-side
    if (this.response) {
      this.response.status = 404;
    }
  }
}

Check the docs for more reference

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.