AngularJS "#!" on url



有人知道什么"#!"方法。在URL上?

我一直在工作,直到那出现,我一直在URL中有一个"#",并希望保持这种方式。目前路由不再起作用,可能是因为此URL更改。

这是一个商业项目的一部分,我不想更改为html5mode。

我尝试使用:

$locationProvider.hashPrefix("");

即使以这种方式纠正URL的路由也有问题

多数民众赞成 hash-bang

修复此用途:

    angular.module('yourApp', [])
    .config(['$locationProvider', function($locationProvider) {
        $locationProvider.hashPrefix('');
    }]);

添加html5mode甚至可以摆脱URL中的"#",但是如果您刷新页面,则会遇到404错误。可以通过对服务器进行配置来解决这一点。为此,您可能想检查漂亮的小教程:

  1. https://scotch.io/tutorials/pretty-urls-in-angularjs-removing-the-hashtag
  2. https://www.theodo.fr/blog/2017/01/pretty-url-in-in-angularjs-angularjs-and-loopback-drop-the/

Stackoverlow中的Hashbang问题还有另一个答案:

执行诸如Twitter,Hash-bang#之类的链接!URL的

您可以在位置提供商中使用html5mode。

$locationProvider.html5Mode(true);

更多信息https://scotch.io/tutorials/pretty-urls-in-angularjs-removing-the-hashtag

在您的app.config

中设置 html5mode true
$locationProvider.html5Mode(true).hashPrefix('*');

最新更新