问题与routerLink指令 [英] Issue with routerLink directive

查看:175
本文介绍了问题与routerLink指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个应用程序Angular2,其中包括一些路由与组件路由器。

I'm writing an Angular2 app that includes some routing with the component router.

截至今天,我采用了棱角分明-2.0.0-beta.3。

As of today, I'm using angular-2.0.0-beta.3.

而在子组件,我尝试使用 routerlink 指令与下面的模板:

while in a child component, I try to use the routerlink directive with the following template:

< A [routerLink] = ['/家庭']>回家< / A>

相反,什么是越来越呈现为:

Instead, what's getting rendered is:

< A>回家< / A>

没有任何异常抛出,把它当作一个无效的锚。

with no exception thrown whatsoever, leaving it as an invalid anchor.

要注意这一点很重要 router.navigate(['家'])按预期工作。

It's important to note that router.navigate(['Home']) is working as expected.

app.component.ts:

app.component.ts:

@Component({
    selector: 'app',
    providers: [WrapperService],
    template: '<router-outlet></router-outlet>',
    directives: [ROUTER_DIRECTIVES]
})
   @RouteConfig([
    { path: '/home', as: 'Home', component: HomeComponent, useAsDefault: true }
])
export class AppComponent {
    constructor() { }
}

home.component.ts

home.component.ts

@Component({
    selector: 'home',
    template: '<a [routerLink]="['/Home']">Go home</a>',
    directives: [ROUTER_DIRECTIVES]
})
export class HomeComponent {
    constructor() { }
}

其实,这些文件应该只显示一个工作链接...当前页面(为简单起见)。

Actually, these files should only show a working link to...the current page (for simplicity).

什么是在这里丢失?

推荐答案

好吧,看来我是缺少在 angular2-polyfills.js 依赖。
我不知道为什么需要它,但显然,它会影响几件事情,其中​​之一是链接的呈现方式。

Well, it seems that I was missing the angular2-polyfills.js dependency. I'm not sure why it is needed, but apparently, it affects several things, among them is the way links are rendered.

这篇关于问题与routerLink指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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