[英]Issue with enabling html5 mode in angular js to remove # from URL
我在stackoverflow和网络中搜索了很多有关此内容的内容,但没有找到直接答案的地方。 因此寻求帮助。 这是我的问题:
我在我的angular js应用程序中启用了“ html5mode”,以从URL中删除“#”符号。 启用后,我能够从URL中成功删除哈希,但得到的样子(在tomcat中运行我的应用程序)
localhost:8080/resources/list/abc
我期待类似的东西
localhost:8080/my-app-context/resources/list/abc
我也像以下方法一样在index.html中添加了基本标记
<base href="/" />
<base href="my-context-path" />
但都没有奏效。
此外,启用html5模式后,我在templateUrl中丢失了文件的相对查找
这是我的代码
resourcesModule.config(['$stateProvider', '$urlRouterProvider', '$locationProvider', function ($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.when('/resources', '/resources/listView/kristin');
$urlRouterProvider.when('', '/resources/list/abc');
$urlRouterProvider.otherwise('/resources/list/abc');
$stateProvider.state('apptemplates', {
url: '/apptemplates',
templateUrl: 'templates/templates.html',
controller: 'TemplatesNavigationController'
})
.state('home', {
templateUrl: 'my-context-path/home/home.html',
controller: 'ResourceManagerController'
})
.state('home.resources', {
url: '/resources',
templateUrl: 'my-context-path/resources/resources.html',
controller: 'ResourcesController'
})
.state('home.resources.listview', {
url: '/listView/{roleID}',
templateUrl: 'resourcemanager-ui/resources/listview/listview.html',
controller: 'ListViewController'
});
$locationProvider.html5Mode(true);
}]);
再进行一次任务。 之前未启用html5模式时,它已映射到
$urlRouterProvider.when('', '/resources/listView/kristin');
但是启用html5模式后,它始终会路由到“其他”。任何特定原因。
提前致谢
我的糟糕,在按如下所示添加基本标记后,一切正常
<base href="/my-context-path/" />
即使相对查找也能正常工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.