伙计们,我只是出于特定的原因,在没有服务器的情况下测试angular应用。有了服务器,它就能正常工作。
我建立我的Angular应用程序使用 ng build --prod
. 我去了dist文件夹,打开我的index.html。
然后我的页眉和页脚正在加载,但主要内容没有加载(所有需要的jscss文件都加载了)。
在路由模块中,主要内容被配置为通过路由加载。指向该路由的组件没有加载。
app.comonent.html
<app-header></app-header>
<router-outlet></router-outlet>
<app-footer></app-footer>
app-routing.module.ts
const routes: Routes = [
{path: '', redirectTo: '/test', pathMatch: 'full'},
{path: 'test', component: TestComponent, canActivate: [TestService]},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
有没有什么办法可以不使用服务器而加载指向路由的组件。在上面提到的TestService中,我也没有进行HTTP调用。
谅谅
如果你没有进行任何HTTP调用,那么它应该可以工作。
编辑 tsconfig.json 并改变 module
属性为 CommonJS
比如说。与普通脚本不同,ES6模块受制于 同源 策略。
然后,尝试像这样构建应用程序 ng build --base-href ./