单击后,Angular2RC4-Primeng菜单栏routerlink无法转到我的路线 [英] Angular2RC4-Primeng Menubar routerlink does not go to my routes after click

查看:47
本文介绍了单击后,Angular2RC4-Primeng菜单栏routerlink无法转到我的路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序使用primeng的菜单栏.我显示了菜单,但是无法在我的应用程序中使路由正常工作.我将特定链接的路由设置为"reports/89",但是当我单击与该链接相对应的菜单时,它将尝试转到"localhost:3000/r/e/p/o/r/t/s/8/9" 这显然不存在. 我检查了包含菜单的项目对象,并且routerLink正确指向"reports/89". 这是怎么回事,以及为什么primeng在链接中的每个字符之间添加/. 我的代码很简单: 私人物品:MenuItem [] = []; 用物品,标签和routerLinks填充物品阵列.

I am using Menubar from primeng for my app. I got the Menu showing, but I wasn't able to make the routing working in my app. I set specific link's route say "reports/89", but when I click the menu corresponding to the link it tries to go to the "localhost:3000/r/e/p/o/r/t/s/8/9" which obviously does not exist. I checked the items object containing my menus and the routerLink is correctly pointing at "reports/89". What is going on here and why primeng puts / among every characters in the link. My codes is simple: private items: MenuItem[] = []; filled the array of items with items, labels and routerLinks.

this.items = [
{
"label": "Lookup",
"routerLink": "/reports/79"
},
{
"label": "Reports",
"routerLink": "/reports/89",
"items": [
  {
    "label": "Lab Results",
    "routerLink": "/reports/3"
  },
  {
    "label": "test Results",
    "routerLink": "/reports/4"
  }
]

所有菜单均正确显示,但我注意到由primeng为菜单项构建的span元素的href设置为#".这可能是问题所在,但不知道为什么要这样设置,因为我提供了自己的routerLinks.

All the menu shows up correctly but I noticed the href of the span elements built by primeng for the menu items are set to "#". this might be the problem but don't know why is it setting that way cause I am providing my own routerLinks.

我没有在组件中进行任何布线,我认为所有操作都将在primeng中完成.

I am not doing any routing in my component I thought all will be done in primeng.

感谢您的帮助

推荐答案

我发现了我的问题.我以错误的格式发送了路由器链接,但是让我失望的是没有出现任何错误并试图走这条疯狂的路.无论如何,对于其他任何遇到此问题的人,routerLink都必须是一个数组,其中包含指向路径的字符串,该字符串的开头是"/".因此,以我为例,应该是routerLink:['/reports/1'].

I found my problem. I was sending the router link in a wrong format, but the thing that trow me off was not getting any error and trying to go that crazy path. Anyway, for anyone else with this issue the routerLink needs to be an array containing the string to the path with "/" at its beginning. So in my case should have been routerLink: ['/reports/1'].

这篇关于单击后,Angular2RC4-Primeng菜单栏routerlink无法转到我的路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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