Просматривая ваш код, я увидел некоторые проблемы.
В login.component.ts флаг переменной объявлен так:
flag: true
Полагаю, вы хотели напишите flag: boolean= true;
в том же файле, в функцию onSumbit при вызове функции входа в систему, после того как вы получили ответ, который вы написали:
this.router.navigate(['./billing']);
Но В app.routing.module.ts маршрут:
{ path: '', component: BillingComponent, canActivate: [AuthGuard] },
Итак, вам нужно было написать:
this.router.navigate(['']);
Итак, в заключение:
onSubmit() {
this.submitted = true;
if (this.loginForm.invalid) {
return;
}
this.loading = true;
this.authenticationService
.login(this.f.username.value, this.f.password.value)
.subscribe(
data => {
//if cart is not empty
if (this.flag == true) this.router.navigate([""]);
else {
this.router.navigate(["cartempty"]);
}
},
error => {
this.alertService.error(error);
this.loading = false;
}
);
}
Очевидно Вы можете определить маршрут для cartEmpty в app.routing.ts :
{ path: 'cartempty', component: CartemptyComponent },