【问题标题】:How to redirect to angular 6 page when user click on account activation in email当用户单击电子邮件中的帐户激活时如何重定向到 Angular 6 页面
【发布时间】:2019-03-01 22:27:50
【问题描述】:
当用户点击电子邮件中的帐户激活时如何重定向到 Angular 6 页面。
我的流程:
1.用户注册账号。
2. 用户从邮件中获取激活账户链接。链接示例:http://localhost/editProfile/{userId} /token/{token}。这应该是我从后端获取 JWT 令牌的 API。
3. 用户点击链接,用户将重定向到编辑个人资料页面。
我的问题是,当用户重定向到编辑个人资料页面时,我不明白如何在用户单击 URL 时从 URL 中获取令牌和 ID。
【问题讨论】:
标签:
angular
angular5
jwt
angular6
【解决方案1】:
您可以通过以下方式实现它(那些没有经过测试,如果我犯了任何错别字/错误,请告诉我。)。简单的路由参数处理。
在您的路线定义中:
export const routes: Routes = [
{ path: '/editProfile/:userId/token/:token', component: MyComponent }
]
在你的路由组件中:
import { ActivatedRoute } from '@angular/router';
import { Subscription } from 'rxjs';
export class EditProfileComponent implements OnInit, OnDestroy {
userId: string;
token: string;
private subscription: Subscription ;
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.subscription = this.route.params.subscribe(params => {
this.userId = params['userId'];
this.token = params['token'];
});
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}
有关路由参数的更多信息,请参阅https://angular-2-training-book.rangle.io/v/v2.3/handout/routing/routeparams.html。