在angular2 rc4问题中找不到RouteConfig函数(普通JS)

时间:2016-07-15 13:28:59

标签: javascript angular angular2-routing angular2-router angular2-router3

升级到RC4后,我遇到此问题配置路由器:

  

ng.router.RouteConfig不是函数

我使用的是纯JavaScript。

这就是我的引导方式:

ng.platform.browser.bootstrap(AppComponent,[
        ng.router.ROUTER_PROVIDERS,
        new ng.core.provide(ng.core.PLATFORM_DIRECTIVES, {useValue: [ng.router.ROUTER_DIRECTIVES], multi: true}),
        new ng.core.provide(ng.common.LocationStrategy, {useClass: ng.common.HashLocationStrategy})
]);

我的主要组件看起来像这样(删除了不必要的代码):

var AppComponent = ng.core
    .Component({
        selector: 'app',
        templateUrl: 'app/app.view.html',
        directives: [
            ng.router.ROUTER_DIRECTIVES
        ]
    })
    .Class({
        constructor: function() {}
    });

AppComponent = ng.router
    .RouteConfig([
        {path: '/search', name:"Search", component: SearchComponent},
        {path: '/results', name:"Results", component: ResultsComponent },
        {path: "*", component: SearchComponent }
    ])
    (AppComponent);

我正在使用: 角度:2.0.0-rc.4 路由器:3.0.0-beta.1

这是我的包括:

    <script src="libs/angular/2.0.0-rc.4/shim.min.js"></script>
    <script src="libs/angular/2.0.0-rc.4/zone.js"></script>
    <script src="libs/angular/2.0.0-rc.4/Reflect.js"></script>
    <script src="libs/angular/2.0.0-rc.4/Rx.umd.js"></script>
    <script src="libs/angular/2.0.0-rc.4/core.umd.js"></script>
    <script src="libs/angular/2.0.0-rc.4/common.umd.js"></script>
    <script src="libs/angular/2.0.0-rc.4/compiler.umd.js"></script>
    <script src="libs/angular/2.0.0-rc.4/platform-browser.umd.js"></script>
    <script src="libs/angular/2.0.0-rc.4/platform-browser-dynamic.umd.js"></script>
    <script src="libs/angular/2.0.0-rc.4/http.umd.js"></script>
    <script src="libs/angular/2.0.0-rc.4/router.umd.js"></script>

1 个答案:

答案 0 :(得分:1)

我猜是RouterConfig而不是RouteConfig

Angular教程Link

中的代码示例
import { provideRouter, RouterConfig }  from '@angular/router';
import { HeroesComponent } from './heroes.component';

const routes: RouterConfig = [
  {
    path: 'heroes',
    component: HeroesComponent
  }
];

<强>更新

.Class({
    constructor: [ ng.router.Router, function(router) {
            router.config([
                { path: '/dashboard', name: 'Dashboard', component: DashboardComponent, useAsDefault: true },
                { path: '/heroes-list', name: 'Heroes', component: HeroesComponent },                
                { path: '/detail/:id', name: 'HeroDetail', component: HeroDetailComponent }
            ]);

    }]
});