I'm working on an Angular project. I got a HTML template with bundle css and js files.
Firstly, I put them inside angular.json and did a normal routing (route every components directly from the app.routing.ts). This method worked perfectly. The outside js and css are loaded.
My build options inside the angular.js,
"options": {
"outputPath": "dist/myNewApp",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets",
],
"styles": [
"src/style.185e1449062630dae048.css"
],
"scripts": [
"src/main.dd20b1e2d0fc8a3dfde3.js"
]
},
my app.routing.ts,
export const routes: Routes = [
{
path: '',
redirectTo: 'index',
pathMatch: 'full',
},
{
path: 'index',
component: IndexComponent,
data: {
title: 'Page Index'
}
},
...
But after I changed the project structure to the lazy loading. The bundle css file is loaded normally. But the JS file is not loaded. It seems like every function inside the bundle js file is not fired (but the browser's console still shows it is loaded inside webpack).
Below is my real used app.routing.ts
export const routes: Routes = [
{
path: '',
loadChildren: () => import('./layout/layout.module').then(t => t.LayoutModule)
},
]
Below is my layout-routing.module.ts,
const routes: Routes = [
{
path: '', component: LayoutComponent,
children: [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', loadChildren: () => import('../pages/index/index.module').then(t => t.IndexModule) },
{ path: 'faq', loadChildren: () => import('../pages/faq/faq.module').then(t => t.FaqModule) },
{ path: 'contact', loadChildren: () => import('../pages/contact/contact.module').then(t => t.ContactModule) },
]
},
];
The webpack shows it is loaded,
Do I miss anything? I already tried to put that js file inside assets and called it from index.html. This way still did not work. Please help.