{ path: 'somepath/**', component: SomeComponent }
import { ActivatedRoute } from '@angular/router';
...
constructor(private route: ActivatedRoute) {}
ngOnInit() { this.route.url.subscribe(url => { const uriSegment = url[url.length - 1]; // 从路径中提取出最后一个部分 if (uriSegment.path === 'somepath') { // 处理你的逻辑 } }); }
import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router';
const routes: Routes = [...];
@NgModule({ imports: [RouterModule.forRoot(routes, { useHash: true })], exports: [RouterModule] }) export class AppRoutingModule { }