我从Angular 2开始,一直在玩路线。 当我没有路线时,一切都正常,但现在每次去/ home,我都会收到这个错误。
Refused to load the font 'data:font/woff;base64,d09GRgABAAAAAIw4ABEAAAABQcAAAQABAAAAAAAAAAAAAAAAAAAAA…hgZiCKVViwAiVhsAFFYyNisAIjRLMJCgMCK7MLEAMCK7MRFgMCK1myBCgGRVJEswsQBAIrAA==' because it violates the following Content Security Policy directive: "default-src 'self'". Note that 'font-src' was not explicitly set, so 'default-src' is used as a fallback.
我正在与HAML合作,但我不认为这是问题所在。 索引仍然是.html扩展,这似乎也没有造成问题。
这是我的index.html。
<html>
<head>
<meta charset="UTF-8">
<title>Freelance Bootcamp</title>
<base href='/'>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<app>App Loading...</app>
</body>
</html>
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { HomepageComponent } from './homepage/homepage.component';
import { AppRoutingModule } from './app-routing.module';
@NgModule({
imports: [
BrowserModule,
HttpModule,
AppRoutingModule
],
declarations: [
AppComponent,
HomepageComponent
],
bootstrap: [
AppComponent
]
})
export class AppModule {}
app.component.ts
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'app',
templateUrl: 'app.component.haml'
})
export class AppComponent {
title: 'Freelance Bootcamp Dashboard';
}
homepage.component.ts
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'homepage',
templateUrl: 'homepage.component.haml'
})
export class HomepageComponent {}
APP-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { HomepageComponent } from './homepage/homepage.component';
const routes: Routes = [
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: 'home', component: HomepageComponent },
]
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})
export class AppRoutingModule {}
当我转到localhost:4200时,redirectTo / home正常工作。 如果我去localhost:4200 / home,当我收到描述的错误并且我的页面卡在App Loading ...屏幕中时。
如果有帮助,我输入了带有angular-cli的应用程序:
ng new application
如果有人能帮助我,那将是惊人的,并提前感谢你。
我希望这是足够的信息。如果没有,请告诉我你还需要知道什么。
答案 0 :(得分:3)
E.g。 font-src
使用data:
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; font-src 'self' data:;">
如果您使用CDN,请根据需要添加,例如fonts.gstatic.com
:
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; font-src 'self' data: fonts.gstatic.com;">