After completing an update from Angular 5.x to 8.0.1, my application compiles but I get the following error at runtime (using ng serve
):
Error: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document.
I've looked at other posts such as: Angular 2 router no base href set, however, my app already has the HTML base element in it. My index.html
is as follows:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MyApp</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<app-root></app-root>
</html>
I can solve the problem by adding:
{
provide: APP_BASE_HREF,
useValue: '/'
}
to my app.modules.ts
, but I'm more interested in understanding why this is now needed, when a bare bones app created with ng new
works without this provider.
body
to the HTML file, and put theapp-root
component in it. – ConnorsFanng serve --baseHref= /
– Joel Joseph