Reputation: 651
Actually i am using angular 5 for my project, I need to remove # from my url.
here is my url
http://localhost:4200/#/product/add
.
After published in my domain it works properly but while refresh the page it shows 404 error because of # in my url. Is it possible to do this?
Need to remove # in url
Upvotes: 14
Views: 26673
Reputation: 7632
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}]
Upvotes: 45