angular 2 router error: router_1.provideRouter is not a function

angular 2 router error: router_1.provideRouter is not a function

当我在 bootstrap 中使用 provideRouter 函数时出现错误 router_1.provideRouter is not a function

angular2-polyfills.js:349 Error: router_1.provideRouter is not a function(…)

这是我的 boot.ts 代码:

import {bootstrap}                     from 'angular2/platform/browser';
import {AppComponent}                  from './app.component';
import {Dashboard1Component}           from './dashboard1.component'
import {TextAreaComponent}             from './textArea.component'
import { provideRouter }               from 'angular2/router';
const router =[
  { path: 'link1', component: TextAreaComponent },
  { path: 'link2', component: Dashboard1Component }
];

bootstrap(AppComponent,[provideRouter(router)]).catch(err => console.error(err));;

这是我在 index.html 中的脚本,用于在不使用 system.config.js 的情况下加载应用程序和库:

<!-- Angular 2 beta parts -->
<script src="http://rawgithub.com/systemjs/systemjs/0.19.6/dist/system.js"></script>
<script src="http://code.angularjs.org/tools/typescript.js"></script>
<script src="http://code.angularjs.org/2.0.0-beta.17/angular2-polyfills.js"></script>
<script src="http://code.angularjs.org/2.0.0-beta.17/Rx.js"></script>
<script src="http://code.angularjs.org/2.0.0-beta.17/angular2.dev.js"></script>
<script src="http://code.angularjs.org/2.0.0-beta.17/router.dev.js"></script>


<!-- 2. Configure SystemJS -->
<script>
  System.config({
    transpiler: 'typescript',
    typescriptOptions: { emitDecoratorMetadata: true },
    packages: {'components': {defaultExtension: 'ts'}}
  });
  System.import('components/boot')
        .then(null, console.error.bind(console));
</script>

请注意,我的代码中没有任何 router_1 变量。我感谢指导。谢谢。

provideRouter 是在 RC.3 附带的新路由器中引入的,在 beta.17

中不可用

另见 https://angular.io/docs/ts/latest/guide/router.html

这解决了我的问题,正如其他人所说,模块是捆绑在一起的,因此您必须更新: systemjs.config.js

var map = {
    '@angular/router':  'node_modules/@angular/router'
}

还有app.routes.ts

import { provideRouter }    from '@angular/router';
import { RouterConfig }     from  '@angular/router';