Angular 角度传感器中的父子路由
当我在angular中执行路由时,我得到了一个类似Angular 角度传感器中的父子路由,angular,routing,angular-routing,Angular,Routing,Angular Routing,当我在angular中执行路由时,我得到了一个类似error:无法匹配任何路由的错误。URL段:“example2/child1”这里我在app.module.ts { path:"for", component: ForComponent }, { path:"example1", component: Example1Component }, { path:"example2",component: Example2Component , chil
error:无法匹配任何路由的错误。URL段:“example2/child1”
这里我在app.module.ts
{ path:"for", component: ForComponent },
{ path:"example1", component: Example1Component },
{ path:"example2",component: Example2Component ,
children: [
{ path:"child1",component:Child1Component },
{ path:"child2",component:Child2Component },
{ path:"child3",component:Child3Component }
]
}
在父组件中,我设置动态链接以导航子组件
<ul>
<li *ngFor="let item of coutry">
<a href="" routerLink="{{item.name}}" >{{item.name}}</a>
</li>
</ul>
-
那我该怎么办?此外,请参见StackOverflow中的相同问题,但不起作用您尚未输入“example2”子级的路径解析:
{ path:"for", component: ForComponent },
{ path:"example1", component: Example1Component },
{ path:"example2",component: Example2Component ,
children: [
{ path:"india",component:Child1Component },
{ path:"child2",component:Child2Component },
{ path:"child3",component:Child3Component }
]
}
当
子数组中没有印度
作为路径时,它如何匹配印度
。您需要它,或者像路径:“:country”
这样的参数路径:
因此,解决方案1:
{ path:"example2",component: Example2Component ,
children: [
{ path:"india",component:Child1Component },
// ...
]
}
或使用参数路径:
{ path:"example2",component: Example2Component ,
children: [
{ path:":country",component:Child1Component },
// ...
]
}
在第二个解决方案中,您编写的另一件事是:
在参数名称之前,这到底是什么意思?它工作得很好,但有了它,我想执行一项任务,比如单击它导航到另一页并显示详细信息的特定链接,但现在它在同一页上打开。请帮助