How to track routing in Angular 2?

I have a component with a shared routing settings file:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { Route } from '../core/route.service';
import { extract } from '../core/i18n.service';
import {CalendarThematicPlanComponent} from './calendar-thematic-plan.component';

const routes: Routes = Route.withShell([
  { path: 'calendar', component: CalendarThematicPlanComponent }
]);

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule],
  providers: []
})

export class CalendarThematicPlanRoutingModule { }

When I type the URL: http://localhost:4200/calendarI am redirected to the home page.

How to trace trace in Angular 2?

+23
source share
2 answers

You can pass the second argument using parameters :

imports: [
    RouterModule.forRoot(
      routes,
      { enableTracing: true } // <-- debugging purposes only
    )
]
+43
source

As the comments in the most acceptable answer show, this one enableTracingdoes not work in the method forChild. A simple workaround is to subscribe to all routing events AppModuleas follows:

export class AppModule {

  constructor(
    private readonly router: Router,
  ) {
    router.events
      .subscribe(console.log)
  }

}
0
source

Source: https://habr.com/ru/post/1683646/


All Articles