【发布时间】:2016-02-17 05:02:38
【问题描述】:
我已经使用 angularJS 框架创建了一个应用程序。在网络浏览器上运行应用程序时,我得到 # 以及我的 url。我尝试了以下方法,
var app = angular.module('missingFound', ['ngRoute','ngCookies','UserModel','homeController','DashBoardContrl','TimeLineContrl','MissingPostContrl','FoundPostContrl','GisContrl'])
.config(['$routeProvider','$locationProvider',
function($routeProvider,$locationProvider) {
$routeProvider.when('/', {
templateUrl : 'views/home.html',
controller : 'homeCtrl'
})
.when('/dashboard',{
templateUrl: 'views/dashboard.html',
controller : 'dashboardCntr',
authenticated : true
})
.when('/timeline',{
templateUrl : 'views/timeline.html',
controller : 'timelineCntr',
authenticated : true
})
.when('/missingForm',{
templateUrl : 'views/missingForm.html',
controller : 'missingCntr',
authenticated : true
})
.when('/foundForm',{
templateUrl : 'views/foundForm.html',
controller : 'foundCntr',
authenticated : true
})
.when('/gisPage',{
templateUrl : 'views/gis.html',
authenticated : true
})
.otherwise({
redirectTo:"/"
});
$locationProvider.html5Mode(true);
/* $locationProvider.html5Mode({
enabled: true,
requireBase: false
});*/
}])
.run(['$rootScope','$location','AuthService',
function($rootScope,$location,AuthService){
$rootScope.$on("$routeChangeStart", function(event, next, current){
if(next.$$route.authenticated){
if(!AuthService.getAuthStatus()){
$location.path('/');
}
}
if(next.$$route.originalPath == '/'){
console.log('Login Page');
if(AuthService.getAuthStatus()){
$location.path(current.$$route.originalPath);
}
}
})
}]);
我的网址是这样的 - http://localhost:7080/Police4/#/
当我通过路由导航到不同的 hmtl 页面时,它在登录后工作正常,但是当我试图复制 URL 路径并在不同的选项卡中打开时,它的显示页面未找到。 在使用 '#' 之前它工作正常,但 URL 看起来很丑。
【问题讨论】:
-
如果只是示例,您能否向我们展示您的其中一条路线在 html 中的样子?
-
我在我的应用程序中使用 html 5,我的 href 看起来像(使用你的代码) href="timeline" 和我的 $location.path 看起来像(使用你的代码)$location.path( “时间线”)
-
使用html5mode需要配置服务器
标签: java angularjs web angularjs-scope