4

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"
  }
]

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.

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

Thanks for any helps

4

1 回答 1

6

我发现了我的问题。我以错误的格式发送路由器链接,但让我失望的是没有出现任何错误并试图走那条疯狂的道路。无论如何,对于遇到此问题的其他任何人,routerLink 都需要是一个数组,其中包含指向路径的字符串,其开头带有“/”。所以在我的情况下应该是 routerLink: ['/reports/1']。

于 2016-08-17T15:17:18.010 回答