【问题标题】:Why angular is adding '#' in each route?为什么 Angular 在每条路线中添加“#”?
【发布时间】:2019-07-02 04:46:30
【问题描述】:

Angular 在我导航的每条路线中都添加了一个“#”。

我尝试修复它,在 index.html 的 head 标签处添加以下代码

    <base href="/" />

有没有办法取出来?

【问题讨论】:

标签: angular


【解决方案1】:

您可能正在使用HashLocationStrategy

Location strategy documentation

检查您的路由设置

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

【讨论】:

    【解决方案2】:

    我已经解决了这个问题。 在 app.module.ts 中,providers 部分有以下内容;

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

    只是评论问题已得到修复的代码

    感谢您的帮助!

    【讨论】:

      猜你喜欢
      • 2019-12-09
      • 1970-01-01
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-26
      相关资源
      最近更新 更多