如何在域之后直接定义查询字符串而不使用前面的斜杠? - ui路由器

时间:2016-05-25 14:58:39

标签: angular-ui-router

我尝试实现一个状态,我可以使用example.com?foo=bar来导航 我有以下状态:

$stateProvider 
  .state('state', {
    url: '?foo'
  });

问题是,它被解释为相对状态。

因此,根据当前状态,我不仅可以在example.com?foo=bar,而且还可以在example.com/path/to/somewhere?foo=bar等其他任何地方结束。

一种解决方案是使用前面的斜杠定义状态:

$stateProvider 
  .state('state', {
    url: '/?foo'
  });

但是我想避免路线为example.com/?foo=bar,这有点难看。

1 个答案:

答案 0 :(得分:0)

检查ui-router文档(https://github.com/angular-ui/ui-router/wiki/URL-Routing),您可以使用^前缀

来使用绝对状态

试试:

$stateProvider 
  .state('state', {
    url: '^?foo'
  });