2

My application cannot show a change in the url address screen. Right now, my application rests at localhost:4200/, and that's it. So I have taken the time to ensure that my navigation links disable the location change:

<a [routerLink]="[screenPath]" skipLocationChange>

And I have one centralized location in a service that handles routing when a change in a screen is necessary:

if (route) {
  this.router.navigate([newRoute], {relativeTo: route, skipLocationChange: true});
} else {
  this.router.navigate([newRoute], {skipLocationChange: true});
}

In my main app routing module, I skip the initial navigation:

@NgModule({
  imports: [RouterModule.forRoot(routes, {initialNavigation: false})],
  ....
})

And in my child routes where my navigation happens, I have guards to prevent certain navigation from happening based on certain conditions:

const routes: Routes = [
{ path: 'somepath', component: SomeFormComponent, canActivate: [WorkFlowGuard] },
{ path: 'anotherpath', component: AnotherFormComponent, canActivate: [WorkFlowGuard]},
....
];

And my WorkFlowGuard returns a simple boolean to determine if the path is allowed or not:

canActivate(next: ActivatedRouteSnapshot,
          state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean
{
  // GRAB CURRENT PATH AND VERIFY
  const path = next.routeConfig.path;
  console.log(`GUARD - verify path: '${path}'`);
  const allow = this.verifyWorkFlow(path);
  return allow;
}

When I am able to access a screen, or when I move to the next screen via a form button, the url up to does NOT change, and that's great! However, any time the WorkFlowGuard gets activated and returns false to prevent me from accessing a certain screen, the url up top gets changed. In other words, if I'm on 'somepath' and I try to access 'anotherpath' when I cannot, the url up top changes from

localhost:4200/

to

localhost:4200/somepath

Why is that happening and what can I do to prevent that URL change from happening?

Nirav
  • 602
  • 1
  • 10
  • 28
user1100412
  • 699
  • 1
  • 10
  • 22

0 Answers0