1

I recently upgraded angular application from RC1 to RC5.

In RC1, I defined routes in app.component.ts:

@RouteConfig([
  { path: '/dashboard', name: 'Dashboard', component: DashboardContainer, useAsDefault: true },
  { path: '/dashboard/:id/:name', name: 'DashboardName', component: DashboardContainer }
])

And in template, I generated links using:

<a [routerLink]="[/Dashboard, routeParams]"> ... </a> where routeParams is { } generates a link <a href="/dashboard">...</a>

<a [routerLink]="[/DashboardName, routeParams]"> ... </a> where routeParams is { id: 2, name: 'joy' } generates a link <a href="/dashboard/2/joy">...</a>

How can I achieve the same in RC5?

6
  • What kind of parameters are they? Route parameters, query parameters? How do the routes look like? Commented Aug 25, 2016 at 5:42
  • route parameters...appended after route path i.e. /path/2/name where 2 & name could be dynamic Commented Aug 25, 2016 at 5:43
  • So passing route parameters as shown in your question doesn't work? I haven't tried it. I always did as demonstrated in my answer. Commented Aug 25, 2016 at 6:00
  • it doesn't accept name of routes in app.routing.ts now...only path & componentName..how can I differentiate routes with parameters if using the same prefix i.e. \dashboard? Commented Aug 25, 2016 at 6:03
  • I see. I somehow assumed it's about parameters (question title). There are no route names in RC.5 only path. Commented Aug 25, 2016 at 6:04

1 Answer 1

0

I assume what you want is something like

<a [routerLink]="['/dashboard', 2]"> ... </a>
<a [routerLink]="['/dashboard/' + 2]"> ... </a>
<a routerLink="{{'/dashboard/' + 2}}"> ... </a>

<a [routerLink]="['/dashboard', 2, name]"> ... </a>
<a [routerLink]="['/dashboard/' + 2 + '/' + name]"> ... </a>

assuming id and name are router parameter.

Passing an array adds them as query or matrix parameters.

<a [routerLink]="['/dashboard', {id: 2, 'name': name}]"> ... </a>
Sign up to request clarification or add additional context in comments.

8 Comments

But, I didn't find if we can put names in route in RC5. it allows only path & component in route definition
I am explaining my question more...Please check it now & reply.
it doesn't work... it gives me url like /dashboard;id:2;name:name which is not what exactly my url should look like.
What is "it"? I mentioned for the last example that it creates query or matrix parameters. Your comment shows matrix parameters.
I tried your last solution to pass id & name in the similar way I was using earlier but it generates /dashboard;id:2;name:name which is not what I want. I want url to be /dashboard/2/name & if I receive it in component, it should give me value for id parameter as 2.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.