如何在 Angular 中应用条件路由,条件是确保上一页已被访问?

How to apply conditional routing in Angular where the condition is to make sure that the previous page has been visited?

我有一个 Angular 网络应用程序,您可以在其中注册您浏览不同的页面:

  1. 填写您的姓名和邮箱
  2. 填写您的密码
  3. 填写您的确认码

因此 URL 从 website.com/intake 变为 website.com/intake/signup 再变为 website.com/intake/confirmation

我的问题是,目前用户可以将 url 从 website.com/intake 更改为 website.com/intake/signup 并在不填写其他信息的情况下完成注册。我想阻止这种情况,但我不确定在这种情况下如何使用路由。

我想确保用户只有在进入第一页并填写后才能进入下一页。现在我知道,如果我制作表单字段 * required 它将不允许用户走得更远,但他仍然可以通过更改 URL.

来绕过它

我该如何解决?

你可以使用守卫。创建一个条件来限制你想要的路线。

如果用户没有填写表格,将他重定向到表格。

Angular guards tutorial