我在 Angular 应用程序中定义了以下状态,我想知道是否可以将模板从另一个状态注入(inject)当前状态?
在下面的 .catch()
中,我有: $state.go('error404');
它将触发 error404 状态并将用户重定向到/404 。然而,我希望发生的是用户停留在触发 404 的同一 URL 上,并且 404 模板只是注入(inject)到页面上。 (所以没有重定向)。这可能吗?
.state('error404', {
url: '/404',
template: '<p style="color:white;">404 NOT FOUND</p>'
})
.state('publicUserProfile', {
url: '/:username',
templateUrl: 'views/public-profile.html',
controller: 'publicProfileController',
resolve: {
userData: ['$http', 'API_URL', '$stateParams', '$state', function ($http, API_URL, $stateParams, $state) {
return $http
.get(API_URL + '/users/' + $stateParams.username)
.catch(function () {
$state.go('error404'); <-- HERE
})
}]
}
});
最佳答案
在这种情况下,您应该删除 url
属性:
.state('error404', {
template: '<p style="color:white;">404 NOT FOUND</p>'
})
关于javascript - Angular UI Router 新 View ,相同的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25230632/