From 4eb57f72e489150f69139c5a20452bc807dd6fd9 Mon Sep 17 00:00:00 2001 From: FlayInAHook Date: Tue, 1 Dec 2020 21:21:32 +0100 Subject: [PATCH] added return url --- src/app/pages/login/login.component.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/app/pages/login/login.component.ts b/src/app/pages/login/login.component.ts index 3835504..2933f3e 100644 --- a/src/app/pages/login/login.component.ts +++ b/src/app/pages/login/login.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { FormControl, Validators } from '@angular/forms'; -import { Router } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { AuthService } from '../../services/auth.service'; @Component({ @@ -15,9 +15,14 @@ export class LoginComponent implements OnInit { loading = false; errorOccurred = false; errorMessage = ''; - constructor(private authService: AuthService, private router: Router) {} - ngOnInit(): void {} + returnUrl : string; + + constructor(private authService: AuthService, private router: Router, private route: ActivatedRoute) {} + + ngOnInit(): void { + this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/tableOverview'; + } login() { this.errorMessage = ''; @@ -29,7 +34,7 @@ export class LoginComponent implements OnInit { this.authService .login(this.email.value, this.password.value) .subscribe( - () => this.router.navigate(['tableOverview']), + () => this.router.navigateByUrl(this.returnUrl), (error) => { this.errorOccurred = true; this.errorMessage =