如果我api.js
res.json({ success:falsse })
在else
上res.redirect('...')
更改404 error
,当我更改数据库中现有对象的网址路径时,没有任何反应。我的问题是使用angular处理404 error
的正确方法,或者我应该使用erroro中间件在服务器端处理 router.get('/seeMore/:id', function(req, res) {
var seeMore = req.params.id;
if(objectid.isValid(seeMore)){
Product.findOne({_id:req.params.id}, function(err, product) {
if(err) throw err
if(!product) {
res.json({ success: false, message: 'Product no found' });
} else {
res.json({ success: true, product: product });
}
})
} else {
res.json({ success:false })
}
});
?
api.js
.when('/register', {
templateUrl: 'app/views/pages/users/register.html',
controller: 'regCtrl',
controllerAs: 'register',
authenticated: false
})
.when('/home', {
templateUrl: 'app/views/pages/users/home.html',
controller: 'mainCtrl',
controllerAs: 'main',
authenticated: true,
})
.when('/seeMore/:id', {
templateUrl: 'app/views/pages/users/nawigacja/zobaczwiecej.html',
controller: 'seeMoreCtrl',
controllerAs: 'seeMore',
authenticated: [true, false],
})
routes.js
.controller('seeMoreCtrl', function($scope,$routeParams,User, $window){
var app = this;
if(data.data.success){
User.readMoreCourse($routeParams.id).then(function(data){
app.currentProduct = data.data.product._id;
console.log(data.data.product)
});
} else {
$window.location.assign('/register')
}
controller.js
.factory('User', function($http){
userFactory = {}
userFactory.readMoreCourse = function(id) {
return $http.get('/api/zobaczwiecej/' + id)
}
return userFactory
});
服务
Course.includes(:content_picture).where("content_picture.id = ?", content_picture_id)
})
答案 0 :(得分:0)
在controller.js中,为什么你只能使用$ location.path(' / register')
controller.js
.controller('seeMoreCtrl', function($scope,$routeParams,User, $window){
var app = this;
if(data.data.success){
User.readMoreCourse($routeParams.id).then(function(data){
app.currentProduct = data.data.product._id;
console.log(data.data.product)
});
} else {
$location.path( "/register" ); //------------> change here
}