【问题标题】:Routes is changing the lookup location of resourcesRoutes 正在改变资源的查找位置
【发布时间】:2018-07-30 17:29:42
【问题描述】:

这篇文章是在link 发布的扩展。之前的问题解决了。

当我添加这条路线时,到目前为止一切正常。

<Route path="/resume-builder/display" component={ResumeDisplay} />

当我刷新此页面时,我可以通过项目中的另一个页面访问此页面,它显示错误

GET http://localhost:8080/resume-builder/dist/bundle.js 404 (Not Found)

display:1 Refused to execute script from 'http://localhost:8080/resume-builder/dist/bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

我不知道为什么我的页面在 /resume-builder/dist/bundle.js 上寻找捆绑包,index.html 中明确提到它必须从中挑选捆绑包

<script src="./dist/bundle.js" ></script>

有没有人知道问题是什么?有什么办法可以解决这个问题?

【问题讨论】:

  • 将脚本的源设置为“/dist/bundle.js”。这是您构建的捆绑包的绝对路径。目前它被设置为一个相对的。这意味着浏览器将尝试相对于当前 URl 路径解析它
  • 已经一样了
  • 不,不一样。你分享了@98​​7654327@ 加入index.html。更新到&lt;script src="/dist/bundle.js"&gt;&lt;/script&gt; 还是有问题吗?
  • 是的,那件事奏效了。你能解释一下吗?

标签: javascript reactjs react-router-v4 react-router-dom


【解决方案1】:

检查您的 webpack 文件,如果没有,请添加 publicPath,如下所示。

 output: {
    filename: '[name].[hash].js',
    path: path.resolve('./dist'),
    publicPath: '/',
  }

从以下链接获取帮助。

https://tylermcginnis.com/react-router-cannot-get-url-refresh/

【讨论】:

  • 你能简单解释一下吗?
  • 您的代码不起作用。但是感谢文档。我会通过它
  • 是有帮助还是卡住了?
  • 我得到了解决方案
猜你喜欢
  • 2020-08-02
  • 1970-01-01
  • 1970-01-01
  • 2012-08-21
  • 2011-11-15
  • 1970-01-01
  • 2011-03-01
  • 1970-01-01
  • 2017-11-17
相关资源
最近更新 更多