Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

I have followed the set up of the plunker given by the angular docs for routing But i keep getting the following errors:

/@angular/router/index"' has no exported member 'provideRouter'

/@angular/router/index"' has no exported member 'RouterConfig'

when trying to use the following imports in my app.router.ts file:

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

I am using typescript in visual studio with commonjs module format.

Here are the dependecies from my 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:

'@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.

I tried deleting the nodule module folder and forcing the npm install to get new files.

QUESTION:

Can someone help me figure out why the exported memebers provideRouter, RouterConfig can not be found?

Thanks

like image 273
J King Avatar asked Jun 17 '16 16:06

J King


2 Answers

I had the same issue, solved it with using Version 3.0.0-alpha.7

Here my 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.

like image 147
chriisi Avatar answered Oct 05 '22 23:10

chriisi


Try to use provideRoutes instead of provideRouter

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

and your routing:

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

UPD For now you don't need provideRouters at all. Just write path and import Routes from '@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);
like image 25
Artem Avatar answered Oct 06 '22 01:10

Artem