error: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document. at new PathLocationStrategy (common.js:453) at provideLocationStrategy (router.js:5547) at callFactory (core.js:21286) at createProviderInstance (core.js:21238) at initNgModule (core.js:21168) at new NgModuleRef (core.js:21895) at createNgModuleRef (core.js:21884) at Object.debugCreateNgModuleRef [as createNgModuleRef] (core.js:23715) at NgModuleFactory.push../node_modules/@angular/core/fesm5/core.js.NgModuleFactory_.create (core.js:24419) at core.js:17765
Asked
Active
Viewed 330 times
0
Hoang Subin
- 6,610
- 6
- 37
- 56
-
Does this answer your question? [Angular 2 router no base href set](https://stackoverflow.com/questions/34535163/angular-2-router-no-base-href-set) – Robert Kühne Feb 29 '20 at 09:53
-
Does this answer your question? [please provide a value for APP\_BASE\_HREF token exception Angular2](https://stackoverflow.com/questions/41526912/please-provide-a-value-for-app-base-href-token-exception-angular2) – Hoang Subin Feb 29 '20 at 10:11
2 Answers
2
As per your error trace, it looks like base href is undefined. Try adding <base href="/"> in index.html.
Index.html
<head>
<base href="/">
<!-- other code-->
</head>
Hope, this helps
Laminoo Lawrance
- 425
- 2
- 8
-
Please click the tick for this comment, for marking this issue as answered. – Laminoo Lawrance Mar 05 '20 at 12:43
1
A predefined DI token for the base href to be used with the PathLocationStrategy. The base href is the URL prefix that should be preserved when generating and recognizing URLs.
const APP_BASE_HREF: InjectionToken<string>;
The following example shows how to use this token to configure the root app injector with a base href value, so that the DI framework can supply the dependency anywhere in the app.
import {Component, NgModule} from '@angular/core';
import {APP_BASE_HREF} from '@angular/common';
@NgModule({
providers: [{provide: APP_BASE_HREF, useValue: '/my/app'}]
})
class AppModule {}
Mehdi Daustany
- 1,018
- 4
- 10
- 23