我正在使用Angular-UI-Router构建一个Web应用程序来处理客户端的导航。 默认的登录页面是URL为“ /”的“首页”。基本模板是使用express从nodejs服务器发送的:
app.get('/', function(req, res) {
res.sendFile('blank.html', {root: './public/views/pages'});
});
客户端app-routes.js
:
.config(['$stateProvider', '$urlRouterProvider',
function ($stateProvider, $urlRouterProvider){
// Redirect to '/' in case of unmatched url
$urlRouterProvider.otherwise('/');
// Setup the states
$stateProvider
.state('home', {
abstract : true,
// Note: abstract still needs a ui-view for its children
// to populate
template : '<ui-view/>'
})
.state('home.homepage', {
url: '/',
templateUrl: '/views/partials/homepage.html',
controller: ''
}).state('home.sign-in', {
url: '/sign-in',
templateUrl: '/views/partials/login.html',
controller: 'AuthenticationCtrl'
});
$stateProvider.state('user', {
abstract : true,
url: '/user',
templateUrl : '/views/pages/user-profile.html',
template: '<ui-view/>',
onEnter: function(){
console.log("enter state");
}
}).state('user.products', {
url: '/user/products',
templateUrl: '/views/partials/products.html',
controller: 'ProductCtrl'
});
输入/
时,将加载模板blank.html
,并在homepage.html
标记中替换<div ui-view/>
。
转到/sign-in
并成功使用用户凭据登录,并将状态设置为user.products
$scope.login = function (credentials) {
Auth.signin(credentials).then(function (data) {
Principle.setToken(data.data, $scope.remember_me);
$state.go('user.products', {});
}, function (res) {
$scope.message = res.message;
$state.go('home.sign-in', {});
});
}
这里的问题是基于模板的user-profile.html
永远不会被加载。它始终显示blank.html
模板
项目结构:
---public
js
+----app.js
+----app-routes.js
views
+--pages
+---blank.html
+---user-profile.html