0
我正嘗試使用angularJS2創建導航菜單。這是我在app.component.ts
:導航菜單中的路由器鏈接路徑與angularJS2
import {provide, Component} from 'angular2/core';
import {APP_BASE_HREF, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, HashLocationStrategy, LocationStrategy, RouteConfig} from 'angular2/router';
import {bootstrap} from 'angular2/platform/browser';
import {Router} from 'angular2/router';
// Terrestri
@Component({
selector: 'terrestri',
template: '/terrestri.html', // WORKS
})
export class TerrestriComponent { }
// Volatili Component
@Component({
selector: 'volatili',
templateUrl: '/volatili.html' --> DOESN'T WORK
})
export class VolatiliComponent { }
// Pesci Us Component
@Component({
selector: 'pesci',
template: 'pesci.html' // WORKS
})
export class PesciComponent { }
@Component({
selector: 'my-app',
directives: [ROUTER_DIRECTIVES],
template: `
<nav>
<ul>
<li><a [routerLink]="['/Volatili']">VOLATILI</a></li>
<li><a [routerLink]="['/Pesci']">PESCI</a></li>
<li><a [routerLink]="['/Terrestri']">TERRESTRI</a></li>
</ul>
</nav>
<router-outlet></router-outlet>
`,
})
@RouteConfig([
{ path: '/volatili', component: VolatiliComponent, as: 'Volatili' },
{ path: '/pesci', component: PesciComponent, as: 'Pesci' },
{ path: '/terrestri', component: TerrestriComponent, as: 'Terrestri' }
])
export class AppComponent {}
我的文件結構是:
-DEV
- app.component.ts
- boot.ts
- terrestri.html
- volatili.html
- pesci.html
我無法導航到「volatili」,這在「templateURL」的定義,而我可以去「佩西「和」terrestri「(它們在」模板「而不是」templateURL「中定義)。
我也試過用:
templateUrl: './volatili.html' --> DOESN'T WORK
templateUrl: 'volatili.html' --> DOESN'T WORK
你有'<基本href =「/」>'的'
'標籤(或'引導()'不知道,但我認爲它起到了重要作用在這裏? –