Javascript 无法删除AngularJS中的#
该应用程序正在使用以下各项:Javascript 无法删除AngularJS中的#,javascript,angularjs,hash,angular-ui-router,single-page-application,Javascript,Angularjs,Hash,Angular Ui Router,Single Page Application,该应用程序正在使用以下各项: AngularJS(v1.6.4) 网页包 用户界面路由器 我们需要路径独立于url中的# 为此,我在代码中添加了以下内容: 在app.js中 /* in the config section */ $locationProvider.hashPrefix(''); $locationProvider.html5Mode(true); var app = angular.module("app", ["ui.router"]); 在index.html中
/* in the config section */
$locationProvider.hashPrefix('');
$locationProvider.html5Mode(true);
var app = angular.module("app", ["ui.router"]);
在index.html中
<!-- under the head section -->
<base href="/">
<head>
<base href="/" />
</head
它给出了以下错误:
无法获取/pathName
但当通过超链接访问时,同样的功能也很好。
此外,在访问“”时,浏览器会将其修改为“”
是否有一种方法可以通过GET请求访问url,或者从webpack进行配置(或者其他方式)
编辑1:
路由代码:
.config(($stateProvider) => {
$stateProvider
.state('pathName', {
url: '/pathName',
template: '<pathNameTemplate />'
});
})
.config($stateProvider)=>{
$stateProvider
.state('路径名'{
url:“/pathName”,
模板:“”
});
})
无html5:
www.site.com/#/section
www.site.com
(#…被忽略)www.site.com/section
www.site.com/section
$locationProvider.hashPrefix('');
这是使用从url中删除#的示例
- AngularJsv1.5.7
- ui路由器v0.4.2
- web.config
/* in the config section */
$locationProvider.hashPrefix('');
$locationProvider.html5Mode(true);
var app = angular.module("app", ["ui.router"]);
app.config
var config = function (locationProvider) {
locationProvider.html5Mode(true);
}
config.$inject = ["$locationProvider"];
app.config(config);
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
index.html
<!-- under the head section -->
<base href="/">
<head>
<base href="/" />
</head
你能粘贴你的路线代码吗?@Avihaym,我认为这不是必需的,但我还是添加了。问题出在你的服务器上。您必须将服务器配置为始终返回基本服务器view@DeblatonJean-菲利普,你能解释一下我怎么做吗;该应用程序本身基本上是一个前端,没有像NodeJS这样的服务器端技术。在不了解您的服务器的情况下,我如何帮助您?您的错误发生在javascript代码尚未加载到浏览器时。你不能用JS代码来处理这个问题