从嵌套的组件使用RouterLink [英] Use RouterLink from a nested component

查看:406
本文介绍了从嵌套的组件使用RouterLink的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

采用了棱角分明2 beta.0

Using Angular 2 beta.0

我有一个组件结构,像这样

I have a component structure like so

App (Has RouteConfig)
 -> List 
 | -> ListItem (Want to use RouterLink from here)

这导致错误:组件列表的路由没有配置

所以我把RouteConfig的列表组件上像这样...

So I put a RouteConfig on the List component like so...

@RouteConfig([
  {path: '/:id', name: 'Details', component: Detail}
])

但我得到的角像的错误错误:儿童路线不允许/表。父母的航线路径上使用...。

我曾尝试之前,并在该路由配置了/目录路径之后添加这些3点......没有成功。

I have tried adding these 3 dots before and after the /list path in that route config... with no success.

路由器上的文档是很轻,虽然我知道这应该是基于关闭UI的路由器,我没有看到并行添加嵌套的路线

The documentation on router is very light and though I know this is supposed to be based off of ui-router, I'm not seeing the parallel to add nested routes

推荐答案

您可以使用它像这样,在父组件:

You can use it like this, in parent component:

@RouteConfig([
  {path: '/', component: HomeComponent, as: 'Home'},
  {path: '/list/...', component: ListComponent, as: 'List'}
])

然后在你的 ListComponent ,定义你的孩子的路线:

And then in your ListComponent, define your child routes:

@RouteConfig([
  { path: '/:id', component: ListItem, as: 'ListItem' }
])

确保 ListComponent 有一个<路由器出口>< /路由器出口> ,以及..

Make sure the ListComponent has a <router-outlet></router-outlet> as well..

这篇关于从嵌套的组件使用RouterLink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆