我将帐户激活电子邮件发送给用户。单击用户激活按钮后重定向我的角度应用程序。但不能重定向准确的路线。实际上是重定向的家庭路线。
如何执行ActivationComponent.ts文件使用电子邮件激活按钮
申请路线
{ path: 'home', component: SearchBarComponent },
{ path: 'user/activation/:email/:token',component: ActivationComponent }
{ path: '**', redirectTo: 'home', pathMatch: 'full' },
电子邮件链接href
www.example.com/#/user/[email protected]&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');
}
);
}
}
你能帮助我吗?如何解决这个问题呢。给出这个示例或教程链接
由于你的路线是'user/activation/:email/:token'
,这意味着获得params的网址应该是这样的:.../user/activation/[email protected]/someRandomNumberAndLetterToken
抓住他们,补充一下
private activatedroute: Activatedroute
在你的构造函数中。
添加此代码添加OnInit
函数的开头
this.email = this.activatedroute.snapshot.params['email'];
this.token = this.activatedroute.snapshot.params['token'];
然后,您可以继续执行脚本。我附上了一张照片,告诉你在控制台中得到了什么(在我的情况下):