我是从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加载卡住……屏幕。
如果有帮助,我通过键入以下命令使用angular-cli生成了应用程序:
ng new application如果有人能帮我解决这个问题,那就太棒了,提前谢谢你。
我希望这是足够的信息。如果没有,请让我知道你还需要知道什么。
发布于 2017-06-12 22:53:47
例如,使用data:的font-src
<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;">https://stackoverflow.com/questions/43078707
复制相似问题