我正在将angular2应用程序迁移到RC2并尝试使用路由器的版本3 alpha。
我跟着设置了 给予的掠夺者 通过 角文档 用于路由
但我不断收到以下错误:
/ @ angular / router / index“'没有导出的成员'provideRouter'
/ @angular / router / index“'没有导出成员'RouterConfig'
尝试在app.router.ts文件中使用以下导入时:
import { provideRouter, RouterConfig } from '@angular/router';
我在visual studio中使用带有commonjs模块格式的typescript。
这是我的packages.json的dependecies
"@angular/common": "2.0.0-rc.2",
"@angular/compiler": "2.0.0-rc.2",
"@angular/core": "2.0.0-rc.2",
"@angular/http": "2.0.0-rc.2",
"@angular/platform-browser": "2.0.0-rc.2",
"@angular/platform-browser-dynamic": "2.0.0-rc.2",
"@angular/router": "3.0.0-alpha.3",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.2",
"systemjs": "0.19.27",
"core-js": "^2.4.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"angular2-in-memory-web-api": "0.0.12"
即使我在我的system.config.js中将angular / route设置为npm cdn,如下所示:
'@ angular / router':'https://npmcdn.com/@angular/router@3.0.0-alpha.3“
我仍然得到错误。
我甚至尝试使用alpha.4,alpha.5和最新的alpha.6版本。
我尝试删除nodule模块文件夹并强制npm install获取新文件。
题:
有人可以帮我弄清楚为什么出口的成员 provideRouter, RouterConfig 无法找到?
谢谢
我有同样的问题,使用版本3.0.0-alpha.7解决了它
这是我的package.json:
"dependencies": {
"@angular/common": "2.0.0-rc.2",
"@angular/compiler": "2.0.0-rc.2",
"@angular/core": "2.0.0-rc.2",
"@angular/http": "2.0.0-rc.2",
"@angular/platform-browser": "2.0.0-rc.2",
"@angular/platform-browser-dynamic": "2.0.0-rc.2",
"@angular/router": "3.0.0-alpha.7",
"@angular/upgrade": "2.0.0-rc.2",
"systemjs": "0.19.31",
"core-js": "^2.4.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"angular2-in-memory-web-api": "0.0.12",
"bootstrap": "^3.3.6",
"contentful": "3.3.14"}
尽管我不会把它称为稳定和新的文档 https://angular.io/docs/ts/latest/guide/router.html 可能有点误导。
我有同样的问题,使用版本3.0.0-alpha.7解决了它
这是我的package.json:
"dependencies": {
"@angular/common": "2.0.0-rc.2",
"@angular/compiler": "2.0.0-rc.2",
"@angular/core": "2.0.0-rc.2",
"@angular/http": "2.0.0-rc.2",
"@angular/platform-browser": "2.0.0-rc.2",
"@angular/platform-browser-dynamic": "2.0.0-rc.2",
"@angular/router": "3.0.0-alpha.7",
"@angular/upgrade": "2.0.0-rc.2",
"systemjs": "0.19.31",
"core-js": "^2.4.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"angular2-in-memory-web-api": "0.0.12",
"bootstrap": "^3.3.6",
"contentful": "3.3.14"}
尽管我不会把它称为稳定和新的文档 https://angular.io/docs/ts/latest/guide/router.html 可能有点误导。
尝试使用provideRoutes而不是provideRouter
import {provideRoutes} from "@angular/router";
和你的路由:
provideRoutes([
{path: '', redirectTo: '/myurl'}
])
UPD
现在你根本不需要提供路由器。只需写入路径并导入
来自'@ angular / router'的路线;
import {RouterModule, Routes} from '@angular/router';
const APP_ROUTES: Routes = [
{path: '', redirectTo: '/somthng', pathMatch: 'full'},
{path: 'somthng', component: SomthngComponent},
{path: 'somthng-list', component: SomthngListComponent}
];
export const your_routing = RouterModule.forRoot(APP_ROUTES);
同时与它搏斗了几个小时,升级到beta7。记得更改system.config.js,因为他们将包名更改为index.js(例如“platform-browser-dynamic / platform-browser-dynamic.js”现在命名为“platform-browser-dynamic / index.js”。
但现在我似乎无法获得默认路由,是吗?
编辑:默认路由只是:
{
path: '',
redirectTo: 'index.php/component/atkstat/dashboard'
},
您需要将此行添加为@ angular / router No umd for router
packages['@angular/router'] = { main: 'index.js', defaultExtension: 'js' };
看看这个的package.json和system.config.js,可以帮到你
http://plnkr.co/edit/y31K7xbiQSVH59qsAOZF?p=preview