【发布时间】:2019-03-04 11:11:52
【问题描述】:
我有一个 Angular 6 应用程序,其中包含一个名为 assets 的组件。当我通过 routerLinks 导航到组件时,页面加载并按预期显示数据:
http://localhost:4200/assets/2
但是,如果我刷新页面,或者直接在浏览器中加载链接,那么我的很多脚本都无法加载:
GET http://localhost:4200/assets/runtime.js net::ERR_ABORTED 404 (Not Found)
Refused to execute script from '<URL>' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
GET http://localhost:4200/assets/polyfills.js net::ERR_ABORTED 404 (Not Found)
我需要在路由器中做些什么吗?或者是什么原因造成的?
【问题讨论】:
-
考虑将此路由添加到您的路由器配置中。
-
在您的路由模块上添加
{useHash: true}。它看起来像这样:RouterModule.forRoot(routes, {useHash: true})。使用哈希,它将能够处理刷新。 -
@YgorAzevedo 你的建议做到了。能不能给个答案。感谢大家的帮助!
标签: angular