AngularJS ui-Router - 在状态之间导航时隐藏 $stateParams

AngularJS ui-Router - hide $stateParams when navigating between states

所以我在我的应用程序中使用 ui-Router 来传递 $stateParams 并以或多或少巧妙的方式在我的控制器中使用它们。重点是,我传递的其中一些 $stateParams 包含敏感信息,例如员工 ID。有没有办法将它们隐藏在 url 中?我在这里看到了一些关于参数的答案,但我不是 100% 确定这就是这些答案所解决的问题。

所以为了清楚起见,我说的是 url 中传递的信息,如下所示:

.state('detail', {
    url: '/detail/:employeeid/:employeename/:employeeteam',
    templateUrl: 'templates/EmployeeReport.html',
    controller: 'ReportController'
})

我想隐藏 employeeidemployeenameemployeeteam

谢谢!

是的。您可以使用 params.

文档 - here

所以你可以修改你的state如下,

.state('detail', {
    url: '/detail',
    templateUrl: 'templates/EmployeeReport.html',
    controller: 'ReportController',
    params: { 
        employeeid: null,   // can initialise to default value
        employeename: null, // can initialise to default value
        employeeteam: null  // can initialise to default value
    }
})

您的控制器代码可以包含 employeeidemployeenameemployeeteam 的值作为 $scope 变量,例如

$scope.idVal = 'id';
$scope.nameVal = 'name';
$scope.teamVal = 'team';

您的HTML将如下所示,

<a ui-sref="detail({
   employeeid:idVal,
   employeename: nameVal,
   employeeteam: teamVal
})"> Details state </a>