内容安全策略:拒绝在lite服务器上执行内联脚本

时间:2019-05-02 11:04:18

标签: angular lite-server

我正在遵循angular的最佳实践来制作PWA。完成生产构建之后(ng built --prod --aot。我也在localhost上从dist运行:npm run dev"dev": "lite-server")。 当浏览器加载时,控制台出现错误:

Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-EzX1NiGgmo59Hi8wZ/thoAxnVbkTfzIAgnVddwzUO3Y='), or a nonce ('nonce-...') is required to enable inline execution. Note also that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.

我试图添加到index.html中: <meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-eval' 'unsafe-inline';">

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

请在路由器模块中像这样实现

RouterModule.forRoot(rootRouterConfig, { useHash: true})