Mám dve cesty :
- domov [ " ]
- o [ 'o' ]
Keď som ísť na /o priamo môj prehliadač, som oznámenie 2 veci :
- môj domov modul je nahratá (keďže som požiadal /o)
- URL je rewritted, ako je tento : /about -> / -> /o
app-smerovanie.modul.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.komponent.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);
}
});
}
}
Uhlové : 13.0.2
Chrome : 96.0.4664.55
OS : MacOS 12.0.1