3

This is my Login component

login-component.ts

ngOnInit() {
        this.loginEventsData = this.route.snapshot.data['loginEventsData'];
        this.isAppActive = this.loginEventsData["A"][0]["IsActive"];
        if (!this.isAppActive) { // I'm getting true here                       
            this.router.navigate(["/maintenance"]);         
}

login.resolver.ts

import { Injectable } from "@angular/core";
import { Router, Resolve, ActivatedRouteSnapshot, RouterStateSnapshot } from "@angular/router";
import { LoginService } from "./login.service";
import { Observable, forkJoin } from "rxjs";
import { map, mergeMap } from "rxjs/operators";
import { DashboardService } from "../dashboard/dashboard.service";

@Injectable()
export class LoginResolver implements Resolve<any> {

    constructor(private loginService: IportLoginService, private dashboardService: DashboardService, private router: Router, ) {

    }

    resolve(
        route: ActivatedRouteSnapshot,
        state: RouterStateSnapshot
    ): Observable<any> {
        let A$ = this.loginService.getApplicationCentre();
        let B$ = this.loginService.getLoginBackgroundImg();
        let CD$ = this.loginService.getLoginId()
            .pipe(
                mergeMap(b => this.loginService.getUserDetails(b)
                    .pipe(map(c => [b, c])))
            );        
        return forkJoin(A$, B$, CD$).pipe(map(([A, B, [C, D]]) => ({ A, B, C, D})));
    }
}

app-routing.module.ts

  const routes: Routes = [
        {
            path: 'login', component: IportLoginComponent, resolve: { loginEventsData: LoginResolver }
        },
        { path: 'termsAndConditions', component: TermsAndConditionsComponent },
        { path: 'maintenance', component: MaintenanceComponent,pathMatch: 'full'}
    ]

    @NgModule({
    imports: [RouterModule.forRoot(routes, { useHash: true, enableTracing: true})],
    exports: [RouterModule],
    providers: [
        LoginResolver
      ]
})

This is the result i'm getting when i'm tracing

Router Event: NavigationCancel
platform-browser.js:211 NavigationCancel(id: 2, url: '/maintenance')
platform-browser.js:211 NavigationCancel {id: 2, url: "/maintenance", reason: "Navigation ID 2 is not equal to the current navigation id 3"}

There is no guard for this component, and i'm getting navigationCancel. Not able to redirect to maintenance component What could be the possible reason?

When i do trace i'm getting Navigation ID 2 is not equal to the current navigation id 3. But I don't have any other navigation running at this point.

Is there any way to cancel everything else and navigate to maintenance component?

Any help would be appreciated!

RS17
  • 773
  • 1
  • 9
  • 23
  • Instead of `this.router.navigate(["/maintenance"])` try, `this.router.navigate(["maintenance"])`. Remove the forward slash – emkay Mar 07 '19 at 07:03
  • I tried it. It's still not working! @emkay – RS17 Mar 07 '19 at 07:14
  • I am not well versed with operators but I have one doubt , if you are returning an Observable from resolve method, how are you able to access it as ` this.isAppActive = this.loginEventsData["A"][0]["IsActive"];` without subscribing it? – emkay Mar 07 '19 at 07:32
  • Same problem once, i've resolved mine with this https://stackoverflow.com/questions/50316794/navigation-id-is-not-equal-to-the-current-router-navigation-id-error Maybe your problem is related a "double" router change. – Simo Mar 07 '19 at 09:22

0 Answers0