UI路由器:没有视图模板的路由视图、路由、路由器、模板

2023-09-14 00:21:12 作者:背着书包闯天下

是否可以设置在 UI-路由器的路由只能有一个控制器?其目的是,在一定的网址,我想这样做的唯一事情是采取行动编程,而不是在视图中显示方面东西。我通过阅读文档,但我不知道如果他们提供一种方式来做到这一点。

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');
    }
  });

当被访问 /去/ 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');
    }
  });