【问题标题】:RouteConfig function not found in angular2 rc4 issue (plain JS)在 angular2 rc4 问题(纯 JS)中找不到 RouteConfig 函数
【发布时间】:2016-07-15 13:28:58
【问题描述】:

升级到 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>

【问题讨论】:

  • 嘿,你知道了吗?我有同样的问题,我已经尝试了好几个小时了......
  • @MaximeLaval 不。我仍然有这个错误,我没有找到解决它的方法。如果您找到解决方案,请作为答案发布,因为我仍然想解决它。

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


【解决方案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 }
            ]);

    }]
});

【讨论】:

  • 如果我尝试使用RouterConfig,我会遇到几乎相同的错误:ng.router.RouterConfig is not a function 在官方备忘单上是ng.router.RouteConfig。这里:angular.io/docs/js/latest/guide/cheatsheet.html
  • 我不知道 angular 2 和 javascript 检查这个答案它可能对你有帮助 stackoverflow.com/questions/33711236/…
  • 关于该问题的问题/答案是旧的,并且使用的是路由器版本 1,即 beta 版本中使用的版本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-24
  • 2020-12-13
  • 2017-02-16
  • 2022-01-02
  • 1970-01-01
相关资源
最近更新 更多