나는 두 가지 경로:
- 홈["]
- 에 대해[''에 대해]
때 나는 이에 대해 직접 브라우저,내가 주 2 일:
- 나의 가정 모듈을 미리 로드(는 반면 나는 요청에 대한/)
- URL rewritted 다음과 같이:/대>/->/에 대
응용 프로그램-routing.모듈입니다.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.구성 요소입니다.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);
}
});
}
}
모:13.0.2
Chrome:96.0.4664.55
OS:MacOS12.0.1