简体   繁体   English

在new @ angular / router 3.0.0-alpha.3 ^中找不到provideRouter和RouterConfig

[英]provideRouter and RouterConfig not found in new @angular/router 3.0.0-alpha.3^

I am migrating an angular2 app to RC2 and trying to use the router's version 3 alpha. 我正在将一个angular2应用程序迁移到RC2并尝试使用路由器的版本3 alpha。

I have followed the set up of the plunker given by the angular docs for routing But i keep getting the following errors: 我已经按照角度文档 给出plunker的设置进行路由但是我不断收到以下错误:

/@angular/router/index"' has no exported member 'provideRouter' / @ angular / router / index“'没有导出的成员'provideRouter'

/@angular/router/index"' has no exported member 'RouterConfig' / @ angular / router / index“'没有导出成员'RouterConfig'

when trying to use the following imports in my app.router.ts file: 尝试在app.router.ts文件中使用以下导入时:

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

I am using typescript in visual studio with commonjs module format. 我在visual studio中使用带有commonjs模块格式的typescript。

Here are the dependecies from my packages.json 这是我的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"

Even if I set the angular/route to the npm cdn in my system.config.js like so: 即使我在我的system.config.js中将angular / route设置为npm cdn,如下所示:

'@angular/router': ' https://npmcdn.com/@angular/router@3.0.0-alpha.3 ' '@ angular / router':' https//npmcdn.com/@angular/router@3.0.0-alpha.3 '

I still get the error. 我仍然得到错误。

I even tried using the alpha.4, alpha.5 and latest alpha.6 version. 我甚至尝试使用alpha.4,alpha.5和最新的alpha.6版本。

I tried deleting the nodule module folder and forcing the npm install to get new files. 我尝试删除nodule模块文件夹并强制npm install获取新文件。

QUESTION: 题:

Can someone help me figure out why the exported memebers provideRouter , RouterConfig can not be found? 有人可以帮我弄清楚为什么导出的memebers提供路由器RouterConfig无法找到?

Thanks 谢谢

I had the same issue, solved it with using Version 3.0.0-alpha.7 我有同样的问题,使用版本3.0.0-alpha.7解决了它

Here my package.json: 这是我的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"}

Altough I wouldn't call it stable and the new Documentation https://angular.io/docs/ts/latest/guide/router.html can be bit missleading. 尽管如此,我不会称之为稳定,新的文档https://angular.io/docs/ts/latest/guide/router.html可能会引起误导。

Try to use provideRoutes instead of provideRouter 尝试使用provideRoutes而不是provideRouter

import {provideRoutes} from "@angular/router";

and your routing: 和你的路由:

provideRoutes([
    {path: '', redirectTo: '/myurl'}
])

UPD For now you don't need provideRouters at all. UPD现在你根本不需要提供路由器。 Just write path and import Routes from '@angular/router'; 只需写入路径并从'@ 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);

Also wrestled with this for a few hours, upgraded to beta7. 同时与此搏斗了几个小时,升级到beta7。 Remember to change system.config.js as they changed packagenames to index.js (eg "platform-browser-dynamic/platform-browser-dynamic.js" is now named "platform-browser-dynamic/index.js". 记得更改system.config.js,因为他们将包名更改为index.js(例如“platform-b​​rowser-dynamic / platform-b​​rowser-dynamic.js”现在命名为“platform-b​​rowser-dynamic / index.js”。

But now I can't seem to get a default route to work, is it ''? 但现在我似乎无法获得默认路由,是吗?

EDIT: Default routing is simply: 编辑:默认路由只是:

{
    path: '',
    redirectTo: 'index.php/component/atkstat/dashboard'
}, 

You need to add this line as @angular/router No umd for router yet 您需要将此行添加为@ angular / router No umd for router

packages['@angular/router'] = { main: 'index.js', defaultExtension: 'js' };

Have a look package.json and system.config.js of this is , may help you 看看这个的package.json和system.config.js,可以帮到你

http://plnkr.co/edit/y31K7xbiQSVH59qsAOZF?p=preview http://plnkr.co/edit/y31K7xbiQSVH59qsAOZF?p=preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM