Mám dvě trasy :
- home [ " ]
- o [ 'about' ]
Když jdu do /o přímo ve svém prohlížeči, jak jsem si všiml 2 věcí :
- můj domov modul je předinstalovaný (vzhledem k tomu, že jsem požádal /o)
- URL je rewritted : /o -> / -> /o
aplikace-směrování.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.komponenta.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);
}
});
}
}
Úhlové : 13.0.2
Chrome : 96.0.4664.55
OS : MacOS 12.0.1