Angularjs使用路由参数变量重新加载页面

时间:2015-01-20 13:23:52

标签: php angularjs

我使用laravel框架作为后端和angularjs作为前端框架,我正在使用的应用程序让用户通过将它们重定向到具有特定内容id的相对URL来编辑某些内容,它完美地工作当用户单击编辑按钮上的并重定向到带有路径参数变量的页面时,如果用户尝试刷新/重新加载同一页面,例如BASE_URL +'edit-files / 14',页面将不再加载。

这是我的代码:

App.config(function ($routeProvider,$locationProvider) {
$routeProvider
.when('/edit-files/:id',{
        templateUrl:BASE_URL+'/public/templates/states/billboard/pages/edit-files.html',
        controller:'editfilesController'
    })

我使用$ location.path重定向到主控制器上的编辑页面:

$scope.editPhoto = function(contentId){
// redirecting to edit page and posting the content id
    $location.path('/edit-files/' + contentId);
}

这是我的代码,用于检索路由参数并将其发送到laravel以获取数据库记录:

App.controller('editfilesController',function($http,$scope,$location,$routeParams){
$scope.id = $routeParams.id;
var data = {
    'id':$scope.id
};
$http({
    method: 'post',
    url: BASE_URL + '/content/edit',
    data: data,
    headers:{'Content-type': 'application/json'}
})

});

1 个答案:

答案 0 :(得分:0)

似乎问题是配置您的路线。试着离开

..
templateUrl: '/public/templates/states/billboard/pages/edit-files.html',
..