我有两条路:
- 家["]
- 关于['关于']
当我去到关于直接与我的浏览器,我已经通知的2件事:
- 我的家庭模块预载的(而我已经请求的/有关)
- 该网址是rewritted这样的:/about->/->/约
应路由。模块。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 { }
应用程序。组成部分。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
铬:96.0.4664.55
操作系统:mac os12.0.1