usmanwalana
usmanwalana

Reputation: 1062

using name in angular 2 when setting up routes

I have an angular 2 app which was written in angular 2 beta 14. I am upgrading it to rc5. I am using the latest router , my package json contains "@angular/router": "3.0.0-rc.1"

Previously routes were configured like :

{path:'/...',name:'LoggedIn',component:LoggedInComponent},
{path:'/auth', name:'Auth', component:AuthComponent}

Now I am doing like this

import { RouterModule , Routes } from '@angular/router';
import {AuthComponent} from "./auth/auth.component";
import {LoggedInComponent} from "./auth/logged-in.component";
import {LOGGED_IN_ROUTES} from "./auth/logged-in.routes";
const APP_ROUTES : Routes = [
    { path : '/...' , name :'LoggedIn' , component : LoggedInComponent , children : LOGGED_IN_ROUTES},
    { path : '' , component : AuthComponent},
    { path : 'auth' , component : AuthComponent},

];
export const routing = RouterModule.forRoot(APP_ROUTES);

I am getting error like

Type '({ path: string; name: string; component: typeof LoggedInComponent; children: Route[]; } | { path...' is not assignable to type 'Route[]'.
  Type '{ path: string; name: string; component: typeof LoggedInComponent; children: Route[]; } | { path:...' is not assignable to type 'Route'.
    Type '{ path: string; name: string; component: typeof LoggedInComponent; children: Route[]; }' is not assignable to type 'Route'.
      Object literal may only specify known properties, and 'name' does not exist in type 'Route'.

Upvotes: 3

Views: 1724

Answers (2)

Asaf Agranat
Asaf Agranat

Reputation: 402

Pass it as data via the data key, like so:

{ path: 'your_path', component: yourComponent, data: { name: 'your_path_name' }}

Read more: https://angular.io/guide/router#configuration

Upvotes: 0

Madhu Ranjan
Madhu Ranjan

Reputation: 17944

name is deprecated now, API has been upgraded since beta, you may read more about it here.

To check how to configure route and the schema of Routes array see this

Hope this helps!!

Upvotes: 1

Related Questions