Angular2 Beta儿童路由器错误:链接" [" NAME"]"不解析终端指令

时间:2016-04-17 22:44:54

标签: typescript angular angular2-routing

我创建了一个测试应用程序来使用Angular2 Beta。我试图从父路线链接到孩子。

每当我尝试将子链接添加到设置时,都会抛出此错误" EXCEPTION:Link" [" / Settings"]"不解析终端指令。在[[' /设置'] AppComponent @ 8:10]"

父路线正常工作。当涉及到子路线时,它有错误。这是我到目前为止所拥有的。

app.component.ts

import {Component} from 'angular2/core';
import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from   'angular2/router';
import {appsComponent} from './apps.component';
import {HomeComponent} from './Home.Component';
import {GPSComponent} from './GPS.component';
import {SettingsComponent} from './Settings.component';

@Component({
selector: 'my-app',
directives: [ROUTER_DIRECTIVES],
template: `
<div class="container">
<div class="row">
<div class="col-md-12">
    <ul class="nav nav-pills">
        <li><a [routerLink]="['/Home']">Home</a></li>
        <li><a [routerLink]="['/Apps']">Apps</a></li>
        <li><a [routerLink]="['/GPS']">GPS</a></li>
        <li><a [routerLink]="['/Settings']">Settings</a></li>
    </ul>
 </div>
</div>
</div>
<router-outlet></router-outlet>

`
})

@RouteConfig([
    { path: '/', component: HomeComponent, as: 'Home' },
    { path: '/apps', component: appsComponent, as: 'Apps'},
    { path: '/gps', component: GPSComponent, as: 'GPS' },
    { path: '/settings/...', component: SettingsComponent, as:'Settings' }
])
export class AppComponent {}

Settings.component.ts

import {Component} from 'angular2/core';
import {Router} from 'angular2/router';
import {UIComponent} from './UI.component';
import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouterOutlet}  from 'angular2/router';

@Component({
  selector: 'settings',
  directives: [ROUTER_DIRECTIVES],
  template: `<h1>Settings Page</h1>
     <ul class="nav nav-stacked">
        <li><a [routerLink]="['/settings','/UI']">Desktop UI</a></li>
      </ul>
     <router-outlet></router-outlet>
`
})

@RouteConfig([
    { path: '/ui', component: UIComponent, as: 'UI'}
 ])
export class SettingsComponent {}

main.ts

import {bootstrap}    from 'angular2/platform/browser';
import {AppComponent} from './app.component';
import {SettingsComponent} from './Settings.component';
import {ROUTER_PROVIDERS} from 'angular2/router';
import {provide} from 'angular2/core';
import {APP_BASE_HREF} from 'angular2/router';
import {LocationStrategy, Location, HashLocationStrategy } from 'angular2/router';

bootstrap(AppComponent, [
ROUTER_PROVIDERS,
provide(APP_BASE_HREF, { useValue: '/' }),
provide(LocationStrategy, { useClass: HashLocationStrategy })
]);

1 个答案:

答案 0 :(得分:1)

您已为path: '/settings/...'声明SettingsComponent路径路径,最后三个点使此路由成为非终端。这意味着您无法导航到/settings您必须提供子路径,即:/settings/info