【发布时间】:2019-12-07 00:15:09
【问题描述】:
我正在设置一个带有路由的 Angular Web 应用程序:https://wei.insa-cvl.org
当我使用此应用程序中的链接时,我可以打开不同的页面。 例如,点击“Mot de passe oublié ?”链接将我带到了好页面:https://wei.insa-cvl.org/auth/forgot-password。 但是,当我尝试通过URL 访问此页面时,出现内部服务器错误。
我认为问题来自.htacess 文件,但即使我删除它,我也总是收到此错误。
.htaccess 文件 (source:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html
</IfModule>
路由:
{path: '', component: ApplicationComponent, canActivate: [AuthGuardService]},
{path: 'auth', component: AuthComponent},
{path: 'auth/forgot-password', component: ForgotPasswordComponent}
...
{path: '**', redirectTo: '/auth', pathMatch: 'full'}
我想通过 URL 访问页面,而不仅仅是点击“应用内链接”。有可能吗?
编辑:万岁,我终于找到了解决方案!我必须将{useHash: true} 添加到我的app-routing.module.ts 并使用哈希URL,例如:https://wei.insa-cvl.org/#/policy
但我不明白,为什么??
【问题讨论】:
-
当您访问index route 时,您的后端会为您的应用程序提供服务。看起来它没有正确配置为在请求另一条路线时为 Angular 应用程序提供服务
-
我终于找到了使用“hash URL”的解决方案。但是我怎样才能为其他路由配置后端呢?
-
这取决于您使用的是什么后端?我自己在使用 .NET Core,您在 Startup.cs 文件中实现此行为。
标签: angular http redirect error-handling