I’m updating an old website with Angular, and one of the requirements I have to meet is that all routes should remain the same as they were (For SEO purposes).
Many of the old website’s routes finish with a slash (Like /my/route/
), and some of them finish with a .html
, like /my/route.html
.
The issue is that routerLink deletes the final slash in every route finishing by a slash (My route is now /my/route
).
How can I make routerLink
to keep the trailing slash ?
A light example can be seen here : AngularTrailingSlash.
5
Answers
I added below to your
app.module.ts
And it now works for me with a trailing slash when
.html
is not thereAdd this code in the main.ts file to keep trailing slash in the routerLink.
Try with Location class extends in
AppModule
like this:app.module.ts:
Even more improved code (based on code from Umesh).
Add on top of
main.ts
:Below code worked for me:
.
.
And add below code in your main.ts:
I have referred below link for this solution:
https://stackblitz.com/github/ssatz/Angular5-Preserve-Trailing-Slash