【问题标题】:AngularJS $location.path adding #!/ before urlAngularJS $location.path 在 url 之前添加 #!/
【发布时间】:2018-09-09 09:54:11
【问题描述】:

我正在尝试使用 AngularJS $location 来设置浏览器的 url,如下所示:

$location.path("/post").search({
    id: post.id
});

但每当我这样做时,网址都会设置为 http://localhost:5000/#!/post?id=0 而不是 http://localhost:5000/post?id=0

#!/ 出现有什么原因吗?

【问题讨论】:

  • 我的回答无效
  • 您的回答很有帮助,但只删除了 !来自 url,所以它会读取 /#/post 这不是我想要的。

标签: angularjs


【解决方案1】:

在应用配置中你应该使用

$locationProvider.html5Mode(true)

【讨论】:

    【解决方案2】:

    如果您想删除此前缀,请将此代码添加到您的配置中:

    appModule.config(['$locationProvider', function($locationProvider) {
      $locationProvider.hashPrefix('');
    }]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-28
      • 1970-01-01
      • 1970-01-01
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多