Angular 2教程上的Meteor JS路由不起作用 [英] Meteor JS Routing on Angular 2 Tutorial doesn't work

查看:46
本文介绍了Angular 2教程上的Meteor JS路由不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从流星js网站制作社交教程,但我陷入了第5步 Routing&多次观看 当我单击链接查看聚会详细信息"时,javascript控制台显示该路由不存在. 这是具有链接的视图中的代码.

I'm trying to make the socially tutorial from the meteor js web but I'm stuck on the step 5 Routing & Multiple Views When I click on the link to see "party details" the javascript console says that the route doesn't exists. This is the code from the view that has the link.

<a [routerLink]="['/party', party._id]">{{party.name}}</a>

这是路线的代码:

const routes: RouterConfig = [
  { path: '', component: PartiesListComponent },
  { path: 'party/:partyId', component: PartyDetailsComponent }
];

这是控制台的输出.

browser_adapter.js:84 EXCEPTION: Error: Uncaught (in promise): Error: Cannot match any routes: 'party;_str=57df4efc74ee85f397a687f3'

推荐答案

最可能的原因是party._id实际上是一个对象,而不是id原语.如果我不得不花钱,我会说这是它的样子

The most likely reason for this is that party._id is actually an object, not the id primitive. If I had to put my money on it, I'd say this it what it looks like

party: {
  _id: {
    _str: '57df4efc74ee85f397a687f3'
  }
}

将对象添加到routerLink数组时,它成为矩阵参数用于上一个路径段.因此,如果上述的实际结构,则将导致

When you add an object into the routerLink array, it becomes a matrix parameter for the previous path segment. So if the above is the actual structure, then would result in

/party;_str=57df4efc74ee85f397a687f3

这是您面临的问题.如果您只想将id值添加到路径,则应提取_str

which is the problem you are facing. If you want to just add the id value to the path, then you should extract the _str

<a [routerLink]="['/party', party._id._str]">

这将为您提供路线

/party/57df4efc74ee85f397a687f3

这就是你想要的.

另请参见:

这篇关于Angular 2教程上的Meteor JS路由不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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