Am două rute :
- acasă [ " ]
- despre [ 'despre' ]
Când mă duc la /despre direct cu browser-ul meu, am observat 2 lucruri :
- casa mea module este preîncărcat (întrucât am solicitat /despre)
- URL-ul este rewritted astfel de prognoze : /despre -> / -> /despre
app-routing.module.t
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{ path: '', loadChildren: () => import('./routes/home/home.module').then(m => m.RoutesHomeModule) },
{ path: 'about', loadChildren: () => import('./routes/about/about.module').then(m => m.RoutesAboutModule) },
{ path: '**', redirectTo: '', pathMatch: 'full' }
];
@NgModule({
imports: [ RouterModule.forRoot(routes, { relativeLinkResolution: 'legacy' }) ],
exports: [ RouterModule ]
})
export class AppRoutingModule { }
app.componenta.ts
import { Component, OnInit } from '@angular/core';
import { NavigationStart, Router } from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.less'],
})
export class AppComponent implements OnInit {
constructor(
private router: Router,
) { }
ngOnInit(): void {
this.router.events.subscribe(event => {
if (event instanceof NavigationStart) {
// outputs "/about" but NEVER "/"
console.log(event.url);
}
});
}
}
Unghiulare : 13.0.2
Chrome : 96.0.4664.55
Sistem de OPERARE : MacOS 12.0.1