How to remove # in url in angular 5? How to remove # in url in angular 5? angular angular

How to remove # in url in angular 5?


You need to change your LocationStrategy to PathLocationStrategy

By default angular use the PathLocationStrategy, that said looks like you're probably defining HashLocationStrategy yourself. Look for some sort of this code in your project:

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

In this case just remove the useHash like so:

RouterModule.forRoot(routes)

Or maybe

[Location, {provide: LocationStrategy, useClass: HashLocationStrategy}]

In this case change HashLocationStrategy to PathLocationStrategy like so:

[Location, {provide: LocationStrategy, useClass: PathLocationStrategy}]