为什么不在Angular JS中使用wotk routeProvider?

时间:2015-05-13 22:27:08

标签: angularjs

我在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'
            });
    })

1 个答案:

答案 0 :(得分:-1)

尝试添加到head代码<base href="/">,如下所示:

<head>
   <base href="/">
</head>