Javascript 角度UI路由器新视图,相同URL
我在Angular应用程序中定义了以下状态,我想知道是否可以将另一个状态的模板注入当前状态 在我下面的Javascript 角度UI路由器新视图,相同URL,javascript,angularjs,angular-ui,Javascript,Angularjs,Angular Ui,我在Angular应用程序中定义了以下状态,我想知道是否可以将另一个状态的模板注入当前状态 在我下面的.catch()中,我有:$state.go('error404')将触发error404状态并将用户重定向到/404。然而,我希望用户停留在触发404的相同URL上,404模板只是被注入到页面中。(因此没有重定向)。这可能吗 .state('error404', { url: '/404', template: '<p style="color:white
.catch()
中,我有:$state.go('error404')代码>将触发error404状态并将用户重定向到/404。然而,我希望用户停留在触发404的相同URL上,404模板只是被注入到页面中。(因此没有重定向)。这可能吗
.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
})
}]
}
});
.state('error404'{
url:“/404”,
模板:“404未找到”
})
.state('publicUserProfile'{
url:“/:用户名”,
templateUrl:'views/public profile.html',
控制器:“publicProfileController”,
决心:{
用户数据:['$http','API_URL','$stateParams','$state',函数($http,API_URL,$stateParams,$state){
返回$http
.get(API_URL++'/users/'+$stateParams.username)
.catch(函数(){
$state.go('error404');在这种情况下,您应该删除url
属性:
.state('error404', {
template: '<p style="color:white;">404 NOT FOUND</p>'
})
.state('error404'{
模板:“404未找到”
})
哇,我怎么会错过呢?谢谢!