Angular 2路由 - 路由器RC3
问题描述:
我试图导航到一个页面后使用routerLink得到一个id,我可以得到。Angular 2路由 - 路由器RC3
问题是链接显示为'/ page; id = 10/component'。我想它显示为 '/页/ 10 /组件'(未矩阵符号 - 没有 'ID =')
在我app.routes.ts:
@RouterConfig = [
{ path: 'page/:id/component', component: MyComponent, data: {id: 'item.id'} }
];
在我的网页:
<a [routerLink]="['page', {id: item.id}, 'component']">
我正在使用最新的Angular 2路由器组件(RC3 Beta 2)。
任何人都知道我在做什么错了?提前致谢。
答
这应该是:
<a [routerLink]="['page', {'id': item.id}, 'component']">
代替:
<a [routerLink]="['/page', item.id, 'component']">
答
从我所看到的,该路由配置不起作用:
{ path: 'page/:id/component', component: MyComponent, data: {id: 'item.id'} }
我认为你真正需要问的是如果最终'/component'
是必要的。如果是这样,您可能需要考虑添加一个child route。
另一种选择是改变路线顺序,改为使用page/component/:id
。我相信routerlink指令将你的URL搜索参数附加到路由的末尾,所以这应该起作用。
同样,最简单的解决方案是从路由配置中删除'/component'
。
谢谢。我尝试过,但仍然得到相同的东西... – Netwraith
我在我正在做的应用程序中做同样的事情。也许你在其他地方有错误。确保你的组件指令列表中有ROUTER_DIRECTIVES。 – Yhlas
奇怪。我的指令列表中也有路由器指令。 – Netwraith