【发布时间】:2021-07-07 12:06:05
【问题描述】:
我已将我的 Angular 11 应用程序托管到远程服务器上的 IIS。 应用程序路由适用于我的 3 个路由中的 2 个。 前两个是从登录页面到“主页”页面和从“主页”到“设计”页面的路由(单击主页也可以返回主页)。这两条路线由
访问this.router.navigate(['design']);
或
this.router.navigate(['home']);
从“设计”页面到“预览”页面不起作用。此路由是通过打开一个新窗口(浏览器中的新选项卡)来完成的
window.open('preview');
404 - 找不到文件或目录。 您要查找的资源可能已被删除、名称已更改或暂时不可用。
我读到我应该将我的 IIS 配置为 URL 重写,但我不明白这个概念。 从 VSCode 和 ng serve
执行此操作时,这一切都有效我的问题是,我缺少的是 IIS 配置吗?如果是,我通过 URL 重写得到了什么 - 当我瞄准正确的 URL 时,MS 网页上的示例似乎与我无关 - http ://servername:port/preview 并收到 404 错误
还是 window.open() 的问题?
我在尝试刷新不是登录页面的页面时遇到相同的 404 - 找不到文件错误。
我已经阅读了this thread,但我仍然不需要 URL 重写
这是 app-routing.module.ts 代码:
const routes: Routes = [
{path: '', component: LoginComponent},
{path: 'design', component: PaletaFormaComponent},
{path: 'preview', component: PreviewFormaComponent},
{path: 'home', component: FirstPageComponent},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
【问题讨论】:
-
window.open() 没有提供协议(http / https)将打开子实例,其路径相对于当前父实例。您确定在您的 IIS 环境中生成的路径是正确的吗?如果它作为页面的子应用程序托管(即myserver.com/AngularApp),您可能需要在 angular.json 中使用 baseHref
标签: angular http-status-code-404 angular-routing angular11