Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2: Argument of type 'Route[]' is not assignable to parameter of type 'Route[]'.

Tags:

angular

I'm getting this error when I updated to the last version of nativescript-angular, I suppose the problem is related to the difference in the version of Angular 2 I'm using and the one used by the module. Is anyone able to tell me what are the right versions I should use to make it work? Mind that my intention to upgrade to the last version of nativescript-angular was to use the RouterExtensions.

Argument of type 'Route[]' is not assignable to parameter of type  'Route[]'.
  Type 'Route' is not assignable to type 'Route'.
    Types of property 'pathMatch' are incompatible.
      Type 'string' is not assignable to type '"full" | "prefix"'.
        Type 'string' is not assignable to type '"prefix"'.
const routes: Route[]

these are my package.json dependencies:

"dependencies": {
    "@angular/common": "2.0.0-rc.4",
    "@angular/compiler": "2.0.0-rc.4",
    "@angular/core": "2.0.0-rc.4",
    "@angular/forms": "0.3.0",
    "@angular/http": "2.0.0-rc.4",
    "@angular/platform-browser": "2.0.0-rc.4",
    "@angular/platform-browser-dynamic": "2.0.0-rc.4",
    "@angular/platform-server": "2.0.0-rc.4",
    "@angular/router": "^3.0.0-rc.1",
    "@angular/router-deprecated": "2.0.0-rc.2",
    "@angular/upgrade": "2.0.0-rc.4",
    "nativescript-angular": "^0.3.1",
    "nativescript-plugin-firebase": "^3.5.3",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.6",
    "tns-core-modules": "^2.3.0-2016-08-29-3966",
    "zone.js": "^0.6.17"
  },

the app.routes.ts:

import { RouterConfig } from '@angular/router';
import { nsProvideRouter} from 'nativescript-angular/router';
import { LoginComponent } from './components/login.component';
import { DashboardComponent } from './components/dashboard.component';


const routes: RouterConfig = [
    {
        path: '',
        redirectTo: '/login',
        terminal: true
    },
    { 
        path: 'login', 
        component: LoginComponent
    },
    {
        path: 'dashboard',
        component: DashboardComponent
    }
];


export const APP_ROUTER_PROVIDERS = [
    nsProvideRouter(routes, { enableTracing: false })
];
like image 949
Andrea Veronesi Avatar asked Feb 07 '23 06:02

Andrea Veronesi


2 Answers

There seems to be no property RouterConfig exported by @angular/router. Try using Routes instead.

const routes: Routes = [ // <==
    {
        path: '',
        redirectTo: '/login',
        terminal: true
    },
    { 
        path: 'login', 
        component: LoginComponent
    },
    {
        path: 'dashboard',
        component: DashboardComponent
    }
];
like image 151
Mohammad Sadiq Rasouli Avatar answered Feb 13 '23 07:02

Mohammad Sadiq Rasouli


I just had the same problem, but source of the problem was that package I was using was built with angular 2 and project was built with angular 4. Although, package works with versions 2+ the problem was that method was expecting old (ng2) Routes but was given new (ng4) Routes. Apparently there is a difference.

My solution was to remove type definition as pass my routes as any type.

like image 40
Miroslav Jonas Avatar answered Feb 13 '23 06:02

Miroslav Jonas