我创建了一个新项目
角cli:1.0.0-beta.17
节点:4.1.0
NPM:3.108
package.json包:

"dependencies": {
    "@angular/common": "~2.0.0",
    "@angular/compiler": "~2.0.0",
    "@angular/core": "~2.0.0",
    "@angular/forms": "~2.0.0",
    "@angular/http": "~2.0.0",
    "@angular/platform-browser": "~2.0.0",
    "@angular/platform-browser-dynamic": "~2.0.0",
    "@angular/router": "~3.0.0",
    "core-js": "^2.4.1",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@types/jasmine": "^2.2.30",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.17",
    "codelyzer": "~0.0.26",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "4.0.9",
    "ts-node": "1.2.1",
    "tslint": "3.13.0",
    "typescript": "2.0.2"
  }

我在src/app下为router创建了一个新文件,代码是:
import { DirectoryComponent } from "./directory/directory.component";
import { HomeComponent } from "./home/home.component";
import { provideRouter } from '@angular/router';

const APP_ROUTES = [
    {path: 'directory', component: DirectoryComponent},
    {path: '', component: HomeComponent}
];

export const APP_ROUTES_PROVIDER = [
    provideRouter(APP_ROUTES)
];

我的主.ts文件是:
import './polyfills.ts';

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
import { AppModule } from './app/';
import { APP_ROUTES_PROVIDER } from "./app/app.route";

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule,[APP_ROUTES_PROVIDER]);

运行代码时,出现错误:
ERROR in [default] /home/newAngularTwo/src/app/app.component.ts:3:9
Module '"/home/sasireka/newAngularTwo/node_modules/@angular/core/index"' has no exported member 'ROUTER_DIRECTIVES'.

ERROR in [default] /home/newAngularTwo/src/app/app.route.ts:3:9
Module '"/home/sasireka/newAngularTwo/node_modules/@angular/router/index"' has no exported member 'provideRouter'.

我犯了什么错?提前谢谢。

最佳答案

角度2现在被释放。版本为“2.0.0”。在发行版中没有provideRouterROUTER_DIRECTIVES。有关角度2释放中的布线,请参见Routing and Navigation

10-05 20:43