我有角4应用程序,我发送重置密码链接到我的电子邮件时,用户提供电子邮件,并点击忘记密码。当用户点击电子邮件中的链接时,它应该直接进入ResetPassword或登录屏幕。但是,当我单击电子邮件中的链接时,它会给出404错误,而不是将用户带到指定的页面(即www.mywebsite.com/ResetPassword?token=token123). )。

我已经为ResetPassword等确定了路线。
{ path: 'ResetPassword', component: ResetPasswordComponent }我是否需要在Range4应用程序中配置任何特定的内容,以便当单击电子邮件链接时,它可以直接转到ResetPassword页面?为什么它给我404错误?
提前谢谢。
发布于 2018-04-20 19:56:23
下面两个步骤解决了我的问题,希望它能帮助到某人:
1)我刚刚注意到,我定义的ResetPassword路由是在'**‘之后(404 -未找到)。
因此,每当它试图查找ResetPassword时,它都会发现在ResetPassword之前没有找到404号。
当我将路由模块更改为在“**”之前定义了ResetPassword时,我就能够从电子邮件链接中直接打开ResetPassword页面。
{ path: 'ResetPassword', component: ResetPasswordComponent }, // Define this one first prior to ** - 404 not found
{ path: '**', component: PageNotFoundComponent } // otherwise redirect to 404-Page Not Found
以前的代码:
{ path: '**', component: PageNotFoundComponent }
{ path: 'ResetPassword', component: ResetPasswordComponent }, // Never reached here as I got 404 prior to reaching this route
但是,这只适用于本地主机。当我将代码部署到主机服务器时,它需要在step#2下面运行。
2)在托管服务器上,我必须用下面的设置更新web.config文件,以便将所有路由重定向到root或index.html。
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="AngularJS Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>感谢@guilherme在下面发布web.config设置的详细信息:
谢谢你的回应!
发布于 2018-04-20 16:55:48
当web服务器找不到所请求的资源时,您需要配置它返回index.html文件,这样就可以加载和接管这个路由。如果您无法配置它,那么您将需要配置HashLocationStrategy来使用URL。这将创建如下所示的URL:www.mywebsite.com/#/login。
发布于 2018-09-05 10:29:07
如果您正在使用Apache,请添加一个包含以下内容的.htaccess文件:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [NC,L]解决了问题。
https://stackoverflow.com/questions/49945990
复制相似问题