# angular-self-repo **Repository Path**: scccwe/angular-self-repo ## Basic Information - **Project Name**: angular-self-repo - **Description**: angualr使用例 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-09-11 - **Last Updated**: 2024-09-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: Angular, angular-router, nest-router ## README # 嵌套路由中二级路由如何获取一级路由中的params ![image-20240911005357931](README.assets/image-20240911005357931.png) 如图所示,在address这个二级路由中,如何获取上层路由的id(此处为12345) ### 核心代码 ```typescript @Component({ selector: 'app-like', standalone: true, imports: [], templateUrl: './like.component.html', styleUrl: './like.component.less' }) export class LikeComponent { private route: ActivatedRoute = inject(ActivatedRoute); userId: string; constructor() { const { userId } = this.route.snapshot.parent!.params; this.userId = userId; } } ``` 通过this.route.snapshot.parent来获取params即可,这样二级路由可以直接用上一级路由的/:id属性