删除#!从我的网址

删除#!从我的网址

问题描述:

我正在使用ui路由器角度路由。我有一些奇怪的#!后我的主要网址。删除#!从我的网址

http://localhost/bootstrap/newBlogProject/index.html#!/home

index.html中后上面的URL,我必须除去此#!迹象。

+0

已使用$ locationProvider.html5Mode(真),但不工作。 –

+0

你使用什么版本的角? – Michael

+0

什么是您的浏览器(带版本)? (非常)旧的浏览器不能使用html5mode。 –

尝试设置$ locationProvider.hashPrefix(''); 下面是我在路由配置中设置hashPrefix的示例。

function config($httpProvider, $routeProvider, $locationProvider) { 
    $routeProvider 
    .when('/', { 
    templateUrl: 'views/home.html', 
    controller: 'HomeController', 
    controllerAs: 'vm', 
    access: { 
     restricted: false 
    } 
    }); 
    $locationProvider.hashPrefix(''); 
} 

您必须启用$ locationProvider的html5Mode才能避免使用hashBang(#!)。

function config($locationProvider) { 
    $locationProvider.html5Mode(true); 
} 

它将强制ui路由器使用历史API来操纵URL并避免它使用hashBang。 像解释here一样。

如果为布尔值,则将html5Mode.enabled设置为值。如果对象设置为enabled,requireBase和rewriteLinks为相应的值。支持的属性:

  • 启用 - {}布尔 - (默认:false)如果为真,将依靠history.pushState以变更网址,在那里的支持。将返回到不支持pushState的浏览器中的哈希前缀路径。

  • requireBase - {boolean} - (默认值:true)启用html5Mode时,指定是否需要存在标记。如果启用且requireBase为true,并且基本标记不存在,则在注入$ location时将会引发错误。请参阅$ location指南以获取更多信息

  • rewriteLinks - {boolean | string} - (默认值:true)启用html5Mode后,将启用/禁用相对链接的URL重写。如果设置为字符串,则URL重写将仅在具有与给定字符串匹配的属性的链接上发生。例如,如果设置为'internal-link',那么只会为链接重写URL。请注意,属性名称规范化不适用于此,因此'internalLink'将不匹配'internal-link'。