我有一个基于github的Angular web应用
我有问题的链接,我发送到注册用户的电子邮件看起来像这样(在微软outlook):
http://rejkid.hopto.org:8080/account/verify-email?token=CA9E3D9587D1884644F70F321AE29847B83D1014F6DCB2552B705B533D583C7A0CDBA57389D92C6C
它应该运行浏览器并激活路由来创建在我的AccountRoutingModule
中定义的angular组件(VerifyEmailComponent
):
const routes: Routes = [
{
path: '', component: LayoutComponent,
children: [
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'verify-email', component: VerifyEmailComponent },
{ path: 'forgot-password', component: ForgotPasswordComponent },
{ path: 'reset-password', component: ResetPasswordComponent }
]
}
];
rejkid.hopto.org
是我的计算机名。如果我使用rejkid.hopto.org
而不是本地主机,它工作得很好,但使用rejkid.hopto.org
由于某种原因会产生一个问题。
我正在运行Tomcat作为我的web服务器(我尝试过ISS,但我得到类似的问题)。
当我使用Postman
执行该链接时,我得到错误The requested resource [/account/verify-email] is not available</p> <p><b>Description</b> The origin server did not find a current representation for the target resource or is not willing to disclose that one exists
.
所以在我看来,web服务器在定位"/account/verify-email"资源,但资源确实存在,因为如果我在URL中使用localhost
,它是可以的。
更新:它不能与URL中的localhost一起工作。它只工作,如果我运行ng服务从Visual Studio Code。
-
您正在尝试使用
rejkid.hopto.org
访问资源。但是你的系统不知道rejkid.hopto.org
是什么。 -
你需要把URL指向本地主机。
-
在
C:WindowsSystem32driversetchosts
文件中添加下面一行(适用于Windows)127.0.0.1 rejkid.hopto.org
查看此链接https://angular.io/guide/deployment#routed-apps-must-fall-back-to-indexhtml。路由应用必须返回到index.html
路由应用程序应该支持"深度链接"。深层链接是一个URL,它指定了应用程序中某个组件的路径。例如,example.com.com/heroes/42是一个指向英雄详情页面的深层链接,该页面显示id为:42的英雄。
当用户从运行中的客户端导航到该URL时没有问题。Angular的路由器会解释URL,并路由到该页面和英雄。
但是点击电子邮件中的链接,在浏览器地址栏中输入链接,或者只是在英雄详情页面上刷新浏览器——所有这些操作都是由浏览器自己处理的,而不是运行的应用程序。浏览器绕过路由器,直接向服务器请求该URL。
静态服务器在收到对example.com.com/的请求时,通常返回index.html。但是它拒绝example.com/heroes/42并返回404 - Not Found错误,除非它被配置为返回index.html。