角新的路由器删除/#从URL [英] Angular New Router remove /# from URL
问题描述
我对角1.4.6和新版本的路由器和0.5.3想从URL删除'/#'。似乎无法找到关于它的互联网上的东西。
I'm on angular 1.4.6 and new router version 0.5.3 and wanted to remove the '/#' from the url. Can't seem to find anything about it on the Internet.
编辑: $ locationProvider.html5mode(真);
提供了以下错误:未捕获的错误:[$喷油器:modulerr]未能实例由于模块的应用程序:
类型错误:$ locationProvider.html5mode不是一个函数
推荐答案
您可以从网址只能在支持HTML5历史API的浏览器中删除#标签。正如你所看到的 rel=\"nofollow\">,它不是在IE9的支持,所以在这种情况下,它会回退到主题标签。
You can remove Hashtag from URLs only in browsers that support HTML5 History API. As you can see here, it's not supported in IE9, so in that case it will fallback to Hashtags.
说了这么多,让你的网址,pretty在做支持的浏览器,你可以启用 html5Mode
使用 $ locationProvider
配置如下图所示。
Having said that, to make your URLs pretty in browsers that do support, you can enable html5Mode
using $locationProvider
config like below.
angular.module('myApp', [])
.config(function($locationProvider){
$locationProvider.html5Mode(true);
});
除此之外,您需要定义应用程序的基本URL角路由器来识别路线。如果您的网址
In addition to this, you need to define the base URL of your application for the angular-router to identify the routes. If your URL is
的http://本地主机:8080 /对myApp /#showLogin
的http://本地主机:8080 /对myApp /#showHomePage
那么你需要使用定义基础URL <碱基GT;
标记像下面
then you need to define the base URL using <base>
tag like below
<head>
<base href="/myApp">
</head>
希望这有助于:)
Hope this helps :)
这篇关于角新的路由器删除/#从URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!