RouteParams in Angular 2 rc1

I tested Angular 2 with beta, and now with rc.0 + some things have changed.

One of them is RouteParams, which cannot be imported from @ angular / router. And when I try to use @ angular / router-deprecated, I get an error message:

ORIGINAL EXCLUSION: There is no provider for RouteParams!

app.component:

@Routes([ { path: '/', component: StartComponent }, {path: '/:projId/:userName', component: ProjectListComponent}, { path: '*', component: StartComponent }, ]) 

Project-list.component:

 import {Component, OnInit} from '@angular/core'; import {RouteParams} from '@angular/router-deprecated'; @Component({ ... }) export class ProjectListComponent implements OnInit { userName:string; projId:string; constructor(private params:RouteParams) { this.userName = params.get('userName'); this.projId = params.get('projId'); } } 

Where can I import RouteParams from now on, or is it something else I'm doing wrong?

Thanks!

+8
javascript angular angular2-routing
source share
2 answers

One of the methods -

  routerOnActivate(curr: RouteSegment) { this.userName = curr.getParam('userName'); this.projId = curr.getParam('projId'); } 
+10
source share

You should use RouteSegment instead of using RouteParams in angular2 RC. like this: -

 import { Component } from '@angular/core'; import { Routes, RouteSegment, ROUTER_DIRECTIVES } from '@angular/router'; @Component({ selector: 'about-item', template: `<h3>About Item Id: {{id}}</h3>` }) class AboutItemComponent { id: any; constructor(routeSegment: RouteSegment) { this.id = routeSegment.getParam('id'); } } @Component({ selector: 'app-about', template: ` <h2>About</h2> <a [routerLink]="['/about/item', 1]">Item 1</a> <a [routerLink]="['/about/item', 2]">Item 2</a> <div class="inner-outlet"> <router-outlet></router-outlet> </div> `, directives: [ROUTER_DIRECTIVES] }) @Routes([ { path: '/item/:id', component: AboutItemComponent } ]) export class AboutComponent { } 
+7
source share

All Articles