Reputation: 215
I have two routes, one goes to a list of blogs and the other to an individual blog. Here are the routes.
const appRoutes: Routes = [
{
path: 'blogs',
component: 'BlogListComponent,
}
{
path: 'blogs/:id',
component: 'BlogComponent,
}
];
I would like to have an alias for my blogs/:id
so blogs/231
shows in the address bar as blogs/blog-title-goes-here
.
Upvotes: 2
Views: 4158
Reputation: 3851
Instead of using the post ID in the URL, you should assign a (unique) slug to each entry, include that slug in the URL (instead of the ID) and also find/identify the requested post via the slug.
For creating the slug, you can use 3rd-party-code such as https://www.npmjs.com/package/slug.
Upvotes: 3