I have a "not found" component:
{
path: '**',
loadComponent: () =>
import('./pages/not-found-pageponent').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?
I have a "not found" component:
{
path: '**',
loadComponent: () =>
import('./pages/not-found-pageponent').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?
Share Improve this question edited Mar 26 at 18:20 marc_s 756k184 gold badges1.4k silver badges1.5k bronze badges asked Mar 26 at 17:40 Sebastián RojasSebastián Rojas 2,8901 gold badge28 silver badges35 bronze badges1 Answer
Reset to default 0Since 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