我尝试实现一个状态,我可以使用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
,这有点难看。
答案 0 :(得分:0)
检查ui-router文档(https://github.com/angular-ui/ui-router/wiki/URL-Routing),您可以使用^前缀
来使用绝对状态试试:
$stateProvider
.state('state', {
url: '^?foo'
});