将所有 $stateParams 重置为默认值

Reset all $stateParams to their default

如何将所有 $stateParams 重置为其定义的默认值?当然,我可以像这样手动重置它们:

$state.go(".", {
  param1: "",
  param2: 0,
  param3: false
});

但最好能自动重置为他们定义的默认值。

$stateProvider
  .state("myState", {
    url: "?param1&param2&param3",
    params: {
      param1: {
        value: "",
        type: "string",
        squash: true
      }, 
      param2: {
        value: 0,
        type: "int",
        squash: true
      }, 
      param3: {
        value: false,
        type: "bool",
        squash: true
      }
    }
  });

手动执行会迫使我在设置值之前查找每个参数值。

而且我完全不想将所有内容都设置为未定义,因为这可能会破坏某些逻辑。

编辑

添加版本信息:

如果您正在使用 ui-sref 那么您还可以提供状态参数,例如 ui-sref="details({msg: ''}) 或者如果您想清除状态参数,当您转换到当前状态时,您可以提及 $state.go('.', {msg: undefined} );

有点晚了,但如果有人遇到同样的问题:

您可以将 inherit TransitionOptions 设置为 false 以强制使用参数的默认值。

$state.go(".", {param1: ""}, {inherit: false});

在此处查看文档: https://ui-router.github.io/ng1/docs/latest/interfaces/transition.transitionoptions.html#inherit