作者:mobiledu2502861197 | 来源:互联网 | 2022-12-03 16:01
我有一个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 '' 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)
我需要在路由器上做些什么还是什么原因?
1> ygorazevedo..:
在路由模块中启用哈希位置。它应该看起来像以下内容。
const routes: Routes = [
{ path: '', component: MyComponent },
{ path: 'my-other', component: MyOtherComponent }
];
@NgModule({
exports: [ RouterModule ],
imports: [ RouterModule.forRoot(routes, {useHash: true}) ]
})
export class MyRoutingModule { }
之后,Angular将能够进行刷新。