[英]How to remove # in url in angular 5?
Actually i am using angular 5 for my project, I need to remove # from my url. 实际上,我在项目中使用的是角度5,因此需要从网址中删除#。 here is my url http://localhost:4200/#/product/add
. 这是我的网址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. 在我的域中发布后,它可以正常工作,但是在刷新页面时,由于我的网址中有# ,它显示404错误。 Is it possible to do this? 是否有可能做到这一点?
Need to remove # in url
You need to change your LocationStrategy to PathLocationStrategy 您需要将LocationStrategy更改为PathLocationStrategy
By default angular use the PathLocationStrategy, that said looks like you're probably defining HashLocationStrategy yourself. 默认情况下,使用PathLocationStrategy进行角度操作,即您可能自己在定义HashLocationStrategy 。 Look for some sort of this code in your project: 在您的项目中寻找这种代码:
RouterModule.forRoot(routes, { useHash: true })
In this case just remove the useHash like so: 在这种情况下,只需如下删除useHash:
RouterModule.forRoot(routes)
Or maybe 或者可能
[Location, {provide: LocationStrategy, useClass: HashLocationStrategy}]
In this case change HashLocationStrategy to PathLocationStrategy like so: 在这种情况下,将HashLocationStrategy更改为PathLocationStrategy,如下所示:
[Location, {provide: LocationStrategy, useClass: PathLocationStrategy}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.