angular - 除非填写表格,否则角度保持在同一页面上
问题描述
用户登录后,他们进入表单。其中有名称和用户名。
http://localhost:4200/form
我希望用户填写表格,然后重定向到任何其他页面。我如何确保即使用户更改了网址,除非他们填写表格,否则他们不会去任何地方。
应用程序路由.module.ts
{
path: "create-profile/:username",
component: profileComponent,
canActivate: [AuthGuard]
},
现在,当用户登录时,它会转到此组件。
submit(form: any) {
this.username = form.username;
this.name= form.name;
this.auth.changePassword(form).subscribe(data => {
this.snackBar.open("profile created", "close", {
duration: 3000
});
});
}
现在在这之后我不知道我该怎么办?我还是角度的新手
解决方案
您的解决方案将是一个两步过程:
创建一个服务来存储表单的状态。例如:有效/无效。一个常见的场景是维护用户是否已登录、具有访问权限等。
为其他路线创建一个路线保护,并使用#1 中的服务检查表单的状态以允许/禁止导航。
推荐阅读
- javascript - 反应钩子停止自我更新
- python - 在 Python 3 中完成线程中的所有任务后,有没有办法返回主菜单循环?
- cloud - Terraform - 错误:[DEBUG] 在输入字节 1 处创建 SSH 密钥非法 base64 数据
- javascript - 仅当我在特定页面上时,如何订阅状态更改?
- html - 如何使用 Flask 将字符串从 python 发送到 HTML 元素
- oauth-2.0 - 如何为 .NET Core Web API 进行安全身份验证?
- python - Django:在用户配置文件的帐户更新中添加和保存新数据
- java - Kafka 教程:java.lang.Object 无法解析
- javascript - Enable scroll with CTRL + middle mouse click instead of link redirection
- javascript - Spotify PKCE code_verifier 不正确