【问题标题】:how to remove # from url in angular 6如何从角度6中的url中删除#
【发布时间】:2019-06-26 07:06:03
【问题描述】:

我正在尝试从 Angular 6 中的 url 中删除 # 符号,但我找不到任何好的解释。 这是我的网址http://localhost:4200/#/homepage.Is 可以从网址中删除哈希吗?

在 app.module.ts 中
{提供:LocationStrategy,useClass:HashLocationStrategy}

在 router.ts 中

导出常量路由:ModuleWithProviders = RouterModule.forRoot(router,{ useHash: true })

我希望输出是http://localhost:4200/homepage

【问题讨论】:

  • 你试过使用哈希定位策略吗?

标签: javascript angular typescript angular6


【解决方案1】:

请记住,这样做将需要您修改服务器 http 配置以支持它,否则在每次页面刷新时您将获得 404..

这是 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;
}
}

【讨论】:

    猜你喜欢
    • 2019-05-07
    • 1970-01-01
    • 2018-11-14
    • 2017-08-12
    • 1970-01-01
    • 2016-01-31
    • 1970-01-01
    • 1970-01-01
    • 2013-07-29
    相关资源
    最近更新 更多