khex
khex

Reputation: 2828

Path variables in Angular 2

@RouteConfig([
  { path: '/post/:post_id', component: PostComponent }
])

Using this classic route strategy /post/1715 I received this JSON data.

{
  "post_id": 1715,
  "title": "The Post Title",
  "urlTitle": "the-post-title",
  "body": "Blah, blah ... blah"
}

But how to redirect router to Stackoverflow URL style /post/1715/the-post-title by adding urlTitle to the link?

Upvotes: 2

Views: 7753

Answers (1)

E. Hein
E. Hein

Reputation: 266

@RouteConfig([
        { path: 'post/:id',   component: PostRedirect },
        { path: 'post/:id/:title', component: PostComponent }
])

The first component reads the id and then redirects to the second one with the title.

complete sample: http://plnkr.co/edit/5BSzvpOH2kAfPAUnJj4O?p=preview

Upvotes: 9

Related Questions