How to remove hash(#) from url in angular

Many times you might see a hash(#) symbol embedded somewhere in your URL in an angular application such as http://localhost:4200/#/auth.
This hash although is added by the routing module of the application, it is not added manually. Though it causes no problem but you might need to remove it.


Solution
In the root routing module file(app.routing.module.ts) or the appropriate routing file, look for the below line

RouterModule.forRoot(routes, {useHash : true})

and change the useHash argument to false or remove it altogether.
Thus, the modified code will be either

RouterModule.forRoot(routes, {useHash : false})

or

RouterModule.forRoot(routes)

Hopefully this will remove the hash symbol from the URL.


Click the clap below if this article helped.

0

Mark Your Impression

Close Menu