I'm submitting a ...
[ x] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request
Current behavior
Everything working perfectly in dev / locahost when working with ng serve (npm start). When I publish in production the tag "base href=" isn't taking into account in order to get the correct path to /assets/i18n/...
Look like it isn't a problem of my Angular project as I'm using this "base href=" to resolve correct path of some picture that are located into /assets/img/ and it's perfectly working.
Expected/desired behavior
Files under /i18n should resolve correct path with "base href=" or another system.
Reproduction of the problem
app.module.ts
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http);
}
...
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
}),
In my "head" tag HTML page:
<base href="http://localhost:8888/wordpress/wp-content/plugins/sagenda-calendar-wp/assets/angular/" />
Build cmd : ng build --prod --aot
Code is published as a WordPress plugin there : https://github.com/Sagenda/sagenda-calendar-wp
Error on the page:
polyfills.bundle.js:1 GET http://localhost:8888/assets/i18n/en.json 404 (Not Found)
But my pictures such as:
<img _ngcontent-c0="" alt="list" height="25" src="./assets/img/octicons/svg/list-unordered.svg" width="25">
are solved without problem...
Please tell us about your environment:
MacOS X 10.13.3
You can set the loader path as 2nd parameter of the TranslateHttpLoader:
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, "./assets/i18n/");
}
The default prefix is /assets/i18n/ - this is why they are loaded from the root assets folder.
Having the assets folder directly under the src folder worked for me. Since I wrongly had it nested in an app folder
Default should be changed to ./assets/i18n/. Makes not sense to hardcode it to /assets/i18n/. Please reopen @CodeAndWeb
Most helpful comment
You can set the loader path as 2nd parameter of the TranslateHttpLoader:
The default prefix is
/assets/i18n/- this is why they are loaded from the root assets folder.