拒绝从 'http://localhost:4200/contacts/styles.js' 执行脚本,因为它的 MIME 类型('text/html')不可执行,并且严格的 MIME[...]

问题描述 投票:0回答:0

我正在开发一个测试应用程序来学习在线课程。

现在我想使用路由参数,所以我的代码是这样的:

在 app.routing.module.ts 中:

const appRoutes: Routes = [
    { path: '', component: LandingComponent, pathMatch: 'full' },
    { path: 'home', component: HomeComponent},
    { path: 'projects', component: ProjectsComponent},
    { path: 'contacts', component: ContactsComponent},
    { path: 'contacts/:id', component: ContactDetailComponent},
    { path: 'prezzi', component: PrezziComponent}
]

问题来了:

如果我使用路径:“contactsId”,则加载 ContactDetailComponent

如果我使用路径:'contacts/id' 或 'contacts/:id' 并尝试联系,例如,contacts/Pippo,控制台会抛出此错误:

pippo:1 Refused to execute script from 'http://localhost:4200/contacts/styles.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

为什么?

angular url-routing angular-routing
© www.soinside.com 2019 - 2024. All rights reserved.