How can I define an angular 4 route with .html in the pattern?
Example: Say the url is mydomain.com/collections/test.html. When I get the route params in a component, I want to retrieve 'test' as the value, and not 'test.html'
File where routing is defined
const routes: Routes = [
{path: 'collections/:tag.html', component: CollectionDetailsComponent},
];
In CollectionDetailsComponent.ts
ngOnInit()
{
this.route.params.forEach((params: Params) =>
{
let tag = params['tag'];
//Here tag contains ".html" at the end
Thanks
I see only 2 ways
add a dummy child route (with the name of your choice of cource)
{path: 'collections/:tag/dummy.html', component: CollectionDetailsComponent},
add .html
to the value
{path: 'collections/:tag', component: CollectionDetailsComponent},
and use foo.html
as tag value.
I haven't tried if .
in the URL causes any issues, but I think to remember that there were related bug reports a long time ago which were fixed.