2

On all of the examples that I see for the new component router the ID is always at the end of the route like this:

@RouteConfig([
    {path: '/email/:id', component: email, as: 'email'},
])

Which you would need a router-link like this to access it:

<a [router-link] = "['./email', {id:1234}">Emails</a>

My question is, how would I write my router-link if my route had the following format?

@RouteConfig([
    {path: '/user/:id/messages', component: email, as: 'email'},
])

When I manually type '/user/1234/messages' into my address bar I can successfully get to the page. But I can't seem to figure out the router-link format that will do the same thing.

Zorthgo
  • 2,857
  • 6
  • 25
  • 37
  • But in my case when i type URL manually into the address bar i cant get to the page ? i am using angular2 alpha 44. andi think this is the issue of angular2. – Pardeep Jain Nov 06 '15 at 05:18
  • I am using Alpha 45, and when I enter the address manually it works perfectly. The problem is writing the router-link tag that works with this type of route. – Zorthgo Nov 06 '15 at 05:26
  • okay i will try with alpha 45. thnx – Pardeep Jain Nov 06 '15 at 12:35
  • @Zorthgo see this [issue](https://github.com/angular/angular/issues/5124#issuecomment-154582754), it explains exactly what you want to do. – Eric Martinez Nov 07 '15 at 00:14
  • @EricMartinez Thanks for the reply. From your link, I am assuming that in order to have my route structured like this '/user/:id/messages' I will have to use a child route. Where the parent route would have '/user/:id/...' and the child route would have the '/messages'. I was hopping that I didn't have to use child route. That I could just specify a full route with a parameter in the middle. Thanks for the reply! :) – Zorthgo Nov 08 '15 at 01:23
  • Yes, I understand, but I understood `/user/...` and `/:id/messages`. Anyway, you can always ask them ;D – Eric Martinez Nov 08 '15 at 01:26
  • Yes, my bad. Exactly, '/user/...' and '/:id/messages'. :) – Zorthgo Nov 08 '15 at 01:27

1 Answers1

0

@brandonroberts answered this question HERE. Basically, the router-link will try to find the route by it's name.

@RouteConfig([
    {path: '/user/:id/messages', component: email, as: 'Email'},
])

So in the example above the name is Email. So the router link-would have to be written like this:

<a [router-link] = "['./Email', {id:1234}">Emails</a>

So router-link will look for a route named "Email" and once it finds it, it will fill in the parameters.

Thanks Brandon for the help!

Zorthgo
  • 2,857
  • 6
  • 25
  • 37