我正在编写一个Angular2应用程序,其中包括一些与组件路由器的路由。
从今天起,我用的是角-2.0.0-beta.3。
在子组件中,我尝试与以下模板一起使用routerlink指令:
<a [routerLink]=['/Home']>Go Home</a>。
相反,呈现的是:
<a>Go Home</a>
没有任何例外抛出,留下它作为一个无效的锚。
需要注意的是,router.navigate(['Home'])正在按预期工作。
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
@Component({
selector: 'home',
template: '<a [routerLink]="['/Home']">Go home</a>',
directives: [ROUTER_DIRECTIVES]
})
export class HomeComponent {
constructor() { }
}实际上,这些文件应该只显示一个工作链接to...the当前页面(为了简单起见)。
这里少了什么?
发布于 2016-02-07 07:06:57
好吧,我似乎错过了angular2-polyfills.js依赖关系。我不知道为什么需要它,但很明显,它会影响到几个方面,其中包括链接的呈现方式。
发布于 2016-02-06 02:10:13
您正在使用的as语法被废弃了一段时间,并重命名为name。
这是我如何定义我的路线。
@RouteConfig([
new Route({ path: '/spreadsheet', component: Spreadsheet, name: 'Spreadsheet' })
])
<a [routerLink]="['/Spreadsheet']">Virtualized Spreadsheet</a>更多信息在这里:http://www.syntaxsuccess.com/viewarticle/routing-in-angular-2.0
https://stackoverflow.com/questions/35234027
复制相似问题