Reputation: 76
I have a route in my angular page as:
{
path: 'topics/:id',
component: TopicsComponent,
},
I absolutely need the :id param to retrieve the topic.
But instead http://myapp.com/topics/123
I want http://myapp.com/topics/the-title-of-the-topic
.
I cannot get topic by Title so I need the id, I don't know how can I do to change the url ? I don't want the id in the url.
I've made some search but I don't find anything.
If you can give me link / direct help, thanks in advance
Upvotes: 1
Views: 1393
Reputation: 3891
You could do the following:
Setup your routing like:
topics/:id/:title
topics/:title/:id
or similar variants.This way you should have access to both. If this gives you problems, you could go for a convention and add the ID
to your titleUrl
and parse it from there. This way you could do topics/:topicUrl
that is made out of :title-:id
, you can write a parser to take the topicUrl
and make an id
and title
out of that.
Upvotes: 2
Reputation: 91
you can directly give the name of string instead of id Like:
{
path: 'topics/:title',
...
}
Upvotes: -1