我在Angular JS中使用routeProvider:
.when('/chat/dialog/:id', {
controller: 'ChatController'
});
在控制器中我有:
if($routeParams.id) {
alert('ok');
}
我的网址如下所示:
http://site-dev.com/chat/dialog/1
链接是:<a href="/chat/dialog/1"></a>
为什么在Angular JS中不能进行路由?
控制器:
.controller('ChatController', ['$scope', '$sce', '$http', '$location', '$anchorScroll', '$timeout', '$routeParams', function ($scope, $sce, $http, $location, $anchorScroll, $timeout, $routeParams, ) {
if($routeParams.id) {
alert('ok');
}
}])
路由:
.config(function ($locationProvider, $routeProvider) {
$routeProvider
.when('/profile/personal/:type', {
templateUrl: '/public/html/personal.html',
controller: 'EditProfileController'
})
/* Chat */
.when('/chat/dialog/:id', {
controller: 'ChatController'
});
})
答案 0 :(得分:-1)
尝试添加到head
代码<base href="/">
,如下所示:
<head>
<base href="/">
</head>