简体   繁体   English

Angular2:我如何从component.ts导航到子项

[英]Angular2: how do i navigate to children from component.ts

I am on homepage /home and want to navigate to children /unitsheet 我在主页/家里,想要导航到儿童/单位表

normally we write this.route.navigate(['home']); 通常我们写这个.route.navigate(['home']); but how do i write it from children to get path as localhost:4200/home/unitsheet 但我如何从儿童写它来获取路径为localhost:4200 / home / unitsheet

 const ROUTER_DATA: Routes = [ { path:'login', component: LoginComponent}, { path:'home', component: HomeComponent, children: [ { path:'unitsheet', component: unitComponent}, ]}, { path:'', redirectTo:'login', pathMatch: 'full'} ] 

this.router.navigate('unitsheet')

or 要么

<a [routerLink]="'unitsheet'">unitsheet</a>

or you can use absolute paths 或者你可以使用绝对路径

<a [routerLink]="'/home/unitsheet'">unitsheet</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在角度,我如何从component.ts访问类方法? - In angular, how do I access a class method from component.ts? Angular - 当它们在 component.ts 文件中启动时,如何从指令内部检测表单事件? - Angular - How do I detect form events from inside a directive when they are initiated in component.ts file? 如何在component.ts中将数据从一个函数传递到另一个函数,angular2 - how to pass data from one function to another in component.ts , angular2 component.ts中的变量不出现在component.html angular2中 - variable in component.ts not appearing in component.html angular2 如何从 angular 中的表单获取输入到 component.ts - How to get input from Form in angular in to component.ts 从Component.ts Angular 6获取数据 - Get Data from Component.ts Angular 6 获取angular2 component.ts上的本地IP - Get local IP on angular2 component.ts 将响应从http.post传递到angular2中的component.ts - Passing response from http.post to component.ts in angular2 如何从.component.ts文件中* ngFor生成的输入中获取值? - How do I get the values from the inputs that *ngFor generate in my .component.ts file? 如何从 service.ts 文件中的 Component.ts 文件调用 function,该文件在 angular 的同一组件中 - How to Call function from Component.ts file in service.ts file which is in the same component in angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM