我将帐户激活电子邮件发送给用户。单击用户激活按钮后,重定向了我的角度应用程序。但不能重定向正确的路线。实际上重定向了本地路线。
如何使用电子邮件激活按钮执行ActivationComponent.ts文件
申请路线
{ path: 'home', component: SearchBarComponent },
{ path: 'user/activation/:email/:token',component: ActivationComponent }
{ path: '**', redirectTo: 'home', pathMatch: 'full' },
电子邮件链接href
www.example.com/#/user/activation?email=example@gmail.lk&token=Mo0hFjfKqY6tPmDzAkiRmEKE5aQDzOtDTGleJmdQsY2DtVOOPnn0Uas1REZaecCE
ActivationComponent
import { SnotifyService } from 'ng-snotify';
import { AuthenticationService } from './../../../http/services/authentication.service';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router, Params } from '../../../../../node_modules/@angular/router';
@Component({
selector: 'app-activation',
templateUrl: './activation.component.html',
styleUrls: ['./activation.component.scss']
})
export class ActivationComponent implements OnInit {
private email: string;
private token: string;
public message: string;
constructor(
private router: ActivatedRoute,
private route: Router,
public auth: AuthenticationService,
private snotifyService: SnotifyService) {}
ngOnInit() {
this.router.queryParams
.subscribe(params => {
this.email = params.email;
this.token = params.token;
});
console.log(this.email);
console.log(this.token);
if (this.email && this.token) {
this.auth.auActivation(this.email, this.token).subscribe(
req => {
this.message = req['success'] ;
}
);
}
}
requestLink(): void {
this.auth.auRequestActivation().subscribe(
req => {
this.snotifyService.success('varification email request sended!', 'Success');
}
);
}
}
你能帮我吗?如何解决这个问题呢。给出了此示例或教程链接
答案 0 :(得分:0)
由于您的路线是'user/activation/:email/:token'
,这意味着获取参数的网址应类似于:.../user/activation/your@email.com/someRandomNumberAndLetterToken
要捕获它们,请添加
private activatedroute: Activatedroute
在您的构造函数中。
添加此代码即可添加OnInit
函数的开头
this.email = this.activatedroute.snapshot.params['email'];
this.token = this.activatedroute.snapshot.params['token'];
然后,您可以继续执行脚本。我随附了一张照片,向您展示您在控制台中得到的东西(以我为例):