我希望我的页面在用户成功注册后重定向到主页。
1)当我在下面的网址中使用时,效果很好。
http://localhost:4200/signup
2)但是,当我使用具有如下引用ID的网址
http://localhost:4200/referral/ONGMwyi1azt
它将再次重定向到
http://localhost:4200/signup
代码:
signUp() {
let params = {};
params["action"] = "addUser";
params["first_name"] = this.first_name;
params["last_name"] = this.last_name;
params["user_name"] = this.user_name;
params["email_id"] = this.email_id;
params["password"] = sha256(this.password);
this._httpService.addUser(this.url, params).subscribe(resp => {
if (
resp["status"] === "User Registration Successful"
) {
// this._zone.run(() => this._router.navigate(["/home"]));
// setTimeout(() => this._router.navigate(["/home"]), 10);
this._router.navigate(["/home"]);
}
});
}
用户成功注册,但未重定向到首页。
在一种情况下工作而另一种情况下失败了,这里到底出了什么问题?谢谢。
答案 0 :(得分:0)
1.Please check routing module as i have mentioned, referral id should pass through routing time.
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{
path: '',
component: ParentComponent,
children: [
{ path: 'referral/:referralId', loadChildren: './Path/referral.module#ReferralModule' }
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class ReferralRoutingModule {}
2.You can use the below code in Referral Component.
constructor(private _route: ActivatedRoute)
ngOnInit() {
this.referralId = this._route.snapshot.params['referralId'];
}