有没有办法用 angular-ui-router 重新加载特定的 ui-view?
Is there way to reload specific ui-view with angular-ui-router?
这是我的测试应用程序http://plnkr.co/edit/OjpZ1h?p=preview
我有 404 错误页面状态,如果此页面不存在,我需要显示请求页面的路径。这里的重定向代码:
$urlRouterProvider.otherwise(function($injector, $location){
var lastPath = $location.path();
$injector.invoke(['$state', function($state) {
var params = angular.copy($state.params);
$state.go('main.error404',params, {location: false});
}]);
return lastPath;
});
除了应用程序已经处于错误状态并且我要转到也不存在的下一页的情况外,一切正常。
在这种情况下不会重新加载,它会显示最后一页的路径。如果我将此代码更改为
$state.go('main.error404',params, {reload: true,location: false});
然后是显示正确的路径,但所有视图都在重新加载,动画看起来很讨厌。
有没有办法用 angular-ui-router 重新加载特定的 ui-view?
感谢 Chris T 的评论,我重写了它:
$stateProvider
.state('main.error404',{
url: '/404/{path}',
views: {
"page@": {
templateUrl: "error.html",
controller: function($scope,$location,$state){
$scope.page = $state.params.path;
}
}
}
});
$urlRouterProvider.otherwise(function($injector, $location){
var lastPath = $location.path();
$injector.invoke(['$state',function($state) {
var params = angular.copy($state.params);
params.path = lastPath;
$state.go('main.error404',params, {location: false});
}]);
return lastPath;
});
每次路径参数更改时都会重新加载状态
这是我的测试应用程序http://plnkr.co/edit/OjpZ1h?p=preview
我有 404 错误页面状态,如果此页面不存在,我需要显示请求页面的路径。这里的重定向代码:
$urlRouterProvider.otherwise(function($injector, $location){
var lastPath = $location.path();
$injector.invoke(['$state', function($state) {
var params = angular.copy($state.params);
$state.go('main.error404',params, {location: false});
}]);
return lastPath;
});
除了应用程序已经处于错误状态并且我要转到也不存在的下一页的情况外,一切正常。
在这种情况下不会重新加载,它会显示最后一页的路径。如果我将此代码更改为
$state.go('main.error404',params, {reload: true,location: false});
然后是显示正确的路径,但所有视图都在重新加载,动画看起来很讨厌。
有没有办法用 angular-ui-router 重新加载特定的 ui-view?
感谢 Chris T 的评论,我重写了它:
$stateProvider
.state('main.error404',{
url: '/404/{path}',
views: {
"page@": {
templateUrl: "error.html",
controller: function($scope,$location,$state){
$scope.page = $state.params.path;
}
}
}
});
$urlRouterProvider.otherwise(function($injector, $location){
var lastPath = $location.path();
$injector.invoke(['$state',function($state) {
var params = angular.copy($state.params);
params.path = lastPath;
$state.go('main.error404',params, {location: false});
}]);
return lastPath;
});
每次路径参数更改时都会重新加载状态