[英]how to remove # from url in angular 6
I am trying to remove the # sign from the url in Angular 6 but I couldn't find any good explanation.我试图从 Angular 6 的 url 中删除 # 符号,但我找不到任何好的解释。 here is my url http://localhost:4200/#/homepage.Is it possible to remove hash from url?
这是我的网址http://localhost:4200/#/homepage。是否可以从网址中删除哈希?
in app.module.ts
在 app.module.ts
{ provide: LocationStrategy, useClass: HashLocationStrategy} { 提供:LocationStrategy,useClass:HashLocationStrategy}
in router.ts
在 router.ts
export const routes: ModuleWithProviders = RouterModule.forRoot(router,{ useHash: true })导出 const 路由: ModuleWithProviders = RouterModule.forRoot(router,{ useHash: true })
I expect the output is http://localhost:4200/homepage我希望输出是http://localhost:4200/homepage
Keep in mind that doing so will require you to modify your server http config to support it otherwise on every page refresh you will get a 404..请记住,这样做将要求您修改服务器 http 配置以支持它,否则在每次刷新页面时您都会得到 404..
this is Nginx example:这是 Nginx 示例:
server {
listen 80;
server_name <YOUR SERVER DOMAIN>;
access_log /var/log/nginx/nginx.vhost.access.log;
error_log /var/log/nginx/nginx.vhost.error.log;
index index.html index.htm;
location / {
root /wwweb/<location to angular dist>/dist;
try_files $uri $uri/ /index.html?$query_string;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.