Webpack开发服务器React Content Security Policy错误 [英] Webpack dev server React Content Security Policy error
问题描述
我的单页应用程序正在webpack-dev-server上运行。我可以在 localhost:8080
上加载和重新加载我的进入路线,并且每次都可以使用。但是我只能通过应用程序内的链接加载 localhost:8080 / accounts / login
,即每当我重新加载 localhost:8080 / accounts / login
从浏览器刷新按钮中我得到
I have my single page app running on webpack-dev-server. I can load and reload my entry route over at localhost:8080
and it works every time. However i can load localhost:8080/accounts/login
only via a link from within the app i.e whenever i reload localhost:8080/accounts/login
from the browser refresh button i get
Cannot GET /accounts/login/
作为服务器响应,在控制台上我得到
as the server response, and on the console i get
内容安全策略:该页面的设置阻止了
资源自身的加载( default-src http :// localhost:8080 )。来源:
;(function installGlobalHook(window){....
Content Security Policy: The page’s settings blocked the loading of a resource at self ("default-src http://localhost:8080"). Source: ;(function installGlobalHook(window) { ....
这是我在单页上的CSP标头应用程序的index.html
This is my CSP header on the single page app's index.html
<meta http-equiv="Content-Security-Policy"
content="default-src * 'self' 'unsafe-inline' 'unsafe-eval'">
我是在我的 webpack.config.json
上也没有使用任何 devtool
我想念什么。
I am also not using any devtool
on my webpack.config.json
. What am i missing.
推荐答案
如果在项目中使用Webpack,请添加 output.publicPath ='/'
并在Webpack配置文件中 devServer.historyApiFallback = true
。
If you use Webpack in your project, please add output.publicPath = '/'
and devServer.historyApiFallback = true
in your webpack config file.
更多信息:手动刷新或手动书写时,react-router url不起作用
这篇关于Webpack开发服务器React Content Security Policy错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!