In my application if personel is not logged in goes to login with return url
this.user=this._session.getEmployee();
if(!this.user){
this.router.navigate(['PA/Login'], {queryParams: {returnUrl:this.url}});
}
and in login component in ngOnInit
I'm trying to reach with code below. in costructor I declared private route: ActivatedRoute
this.url=this.route.snapshot.paramMap.get('returnUrl');
this is my route configuration
const routes: Routes = [
{path:"",redirectTo:"PA/Login",pathMatch:"full"},
{path:"PA",redirectTo:"PA/Login",pathMatch:"full"},
{path:"PA/Home",component:HomeComponent},
{path:"PA/Email/:url",component:EmailComponent},
{path:"PA/Login",component:LoginComponent},
{path:"PA/Login?returnUrl=:returnUrl",component:LoginComponent},
];
but it returns null. Where do I make mistake?
Thanks for you helps
You are trying to get the query params from paramMap
, when you should get through queryParamMap
:
this.route.snapshot.queryParamMap.get('returnUrl');
Also, you don't need the following line in router config:
{path:"PA/Login?returnUrl=:returnUrl",component:LoginComponent},
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.