typescript 在新的@angular/router 3.0.0-alpha.3^ 中找不到 provideRouter 和 RouterConfig
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37886276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
provideRouter and RouterConfig not found in new @angular/router 3.0.0-alpha.3^
提问by J King
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 givenby the angular docsfor routing But i keep getting the following errors:
我也跟着立的给出plunker由角文档路由但我不断收到以下错误:
/@angular/router/index"' has no exported member 'provideRouter'
/@angular/router/index"' has no exported member 'RouterConfig'
/@angular/router/index"' 没有导出成员 'provideRouter'
/@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 模块格式的打字稿。
Here are the dependecies from my packages.json
这是我的packages.json 中的依赖项
"@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/[email protected]'
'@angular/router': ' https://npmcdn.com/@angular/[email protected]'
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.
我尝试删除结节模块文件夹并强制 npm install 获取新文件。
QUESTION:
问题:
Can someone help me figure out why the exported memebers provideRouter, RouterConfigcan not be found?
有人可以帮我弄清楚为什么找不到导出的成员 provideRouter,RouterConfig吗?
Thanks
谢谢
采纳答案by chriisi
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.htmlcan be bit missleading.
虽然我不会称它为稳定的,而且新的文档https://angular.io/docs/ts/latest/guide/router.html可能有点误导。
回答by Artem Ignatiev
Try to use provideRoutes instead of provideRouter
尝试使用 provideRoutes 而不是 provideRouter
import {provideRoutes} from "@angular/router";
and your routing:
和你的路由:
provideRoutes([
{path: '', redirectTo: '/myurl'}
])
UPDFor now you don't need provideRouters at all. Just write path and import Routes from '@angular/router';
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);
回答by Sawri
Also wrestled with this for a few hours, upgraded to beta7. Remember to change system.config.js as they changed packagenames to index.js (e.g. "platform-browser-dynamic/platform-browser-dynamic.js" is now named "platform-browser-dynamic/index.js".
也为此折腾了几个小时,升级到beta7。请记住更改 system.config.js,因为它们将包名更改为 index.js(例如,“platform-browser-dynamic/platform-browser-dynamic.js”现在被命名为“platform-browser-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'
},
回答by Long Field
You need to add this line as @angular/router No umd for router yet
您需要将此行添加为@angular/router 路由器尚无 umd
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 这是什么,可能对你有帮助