I am working on an Angular Universal Application. I want to create dynamic routes with custom prefix but I am unable find any helpful documentation related with my case. Any Help will be appreciated...
Details:
What I have is, I have 4 pages with 4 different dynamic URLs which are:
- Home Page (
http://example.com/
) - Category Page (
http://example.com/{category_name}
) - Sub Category Page (
http://example.com/{category_name}/{sub_category_name}
) - Product Page (
http://example.com/p{product_id}-{product_name}
) - User Page (
http://example.com/user{user_id}-{user_name}
)
What I did
I have registered a single route to handle Home, Category and Sub Category Pages because they have same UI with dynamic category levels mentioned below,
RouterModule.forRoot([
{path: '**', component: HomeComponent, data: {title: 'Home', description: 'Homepage - quick overview.'}}
])
Struggling:
Now, I am unable to add the routes for Product and User Page, I am unable to understand, how to add p
and user
prefixs after slash and before ids
in Product and User Pages respectively. Without these prefixs, routing is working fine.
Examples of Required URLs for Product & User Pages
- Product Page (http://example.com/p123-Product-Name)
- User Page (http://example.com/user123-User-Name)
I am using @angular/router
for routing.
Thanks in advance.