问题描述
是否可以在只有控制器的 ui-router
中设置路由?目的是在某个 URL 上,我唯一想做的就是以编程方式采取行动,而不是根据视图显示任何内容.我已经通读了文档,但我不确定他们是否提供了一种方法来做到这一点.
Is it possible to setup a route in ui-router
that only has a controller? The purpose being that at a certain URL, the only thing I'd like to do is take action programatically, and not display anything in terms of a view. I've read through the docs, but I'm not sure if they offer a way to do this.
是的,我读过这个:https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-open-a-dialogmodal-at-a-certain-state,但这并不是我想要的.
Yes, I have read this: https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-open-a-dialogmodal-at-a-certain-state, but that is not quite what I am looking for.
例如,假设我有一个带有视图的基本主体:
For example, let's just say I have a basic body with view:
<body ui-view></body>
还有一些基本配置:
// Routes
$stateProvider
.state('myaction', {
url: "/go/myaction",
onEnter: function() {
console.log('doing something');
}
});
当访问/go/myaction
时,视图为空白.可以这样做吗?
When /go/myaction
is visited, the view is blank. Is it possible to do this?
推荐答案
我能够通过将我正在执行编程操作的无头状态重定向到无头状态结束时带有视图的状态来解决这个问题:
I was able to solve this problem by redirecting the headless state I was taking programmatic action in, to a state WITH a view at the end of the headless state:
$stateProvider
.state('myaction', {
url: "/go/myaction",
onEnter: function() {
console.log('doing something');
}
controller: function($state) {
$state.go('home');
}
});
这篇关于ui-router:没有视图模板的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!