简体   繁体   English

如何使用角度ui.router过渡到多个视图

[英]How to transitionTo multiple views using angular ui.router

I'm having some issues with the ui.router. 我在ui.router遇到问题。 I've defined what i thought were 3 states that i could flip between 我已经定义了我认为可以在三个状态之间切换的三个状态

$stateProvider
        .state('rackOrShelf', {
            url: '/information',
            templateUrl: 'Scripts/html/rackOrShelfPartial.html'
        }).state('door', {
            url: '/information',
            templateUrl: 'Scripts/html/doorPartial.html'
        }).state('frame', {
            url: '/information',
            templateUrl: 'Scripts/html/framePartial.html'
        });

I've an html page that defines a header to display common stuff at the top. 我有一个html页面,该页面定义了一个标头,以在顶部显示常见内容。 further down within div i have the ui-view placeholder 在div中更远的地方我有ui-view占位符

the html page defines an ng-controller that does some work and returns a json model, one of the parameters being a html页面定义了一个ng-controller,它会执行一些工作并返回json模型,其中一个参数是

model.Transiton = 'frame';

which i then use to call this. 然后我用它来称呼它。 $state.transitionTo(model.Transiton); $ state.transitionTo(model.Transiton);

Problem is if model.Transition = 'rackOrShelf' or 'door' ui.router seems to work fine. 问题是,如果model.Transition ='rackOrShelf'或'door'ui.router看起来工作正常。 but if i do model.Transition = 'frame' i always appear to get the contents of the door templateUrl? 但是,如果我做model.Transition ='frame',我总是会得到门templateUrl的内容吗? Why is this? 为什么是这样?

this is an SPA too. 这也是SPA。 and i use $routeProvider 我用$ routeProvider

$routeProvider
      .when("/main", {
          templateUrl: "Scripts/html/main.html",
          controller: "mainController"
      }).when("/information", {
          templateUrl: "Scripts/html/information.html",
          controller: "informationController",
          reloadOnSearch: false
      })
      .otherwise({ redirectTo: "/main" });

so here is an update, this seems to work. 所以这里是一个更新,这似乎可行。

$stateProvider
        .state('empty', {
            template: '<div></div>'
        })
        .state('rackOrShelf', {
            templateUrl: 'Scripts/html/rackOrShelfPartial.html'
        }).state('door', {
            templateUrl: 'Scripts/html/doorPartial.html'
        }).state('frame', {
            templateUrl: 'Scripts/html/framePartial.html'
        }).state('information', {
            url: '/information',
            params: {partial: 'empty'},
            controller: function ($state) {
               $state.go($state.params.partial);
            }
        });

And in my angular controller i have something like this. 在我的角度控制器中,我有这样的东西。

 $state.transitionTo('information', { partial:<'door' || 'frame' || 'rackOrShelf'> });

All three of your states have the exact same URL. 您的所有三个州都具有完全相同的URL。 I'm not sure if giving these unique URL's will fix your issue, but it will certainly reduce other issues you might have: 我不确定提供这些唯一的URL是否可以解决您的问题,但肯定会减少您可能遇到的其他问题:

$stateProvider
    .state('information', {
        abstract: true,
        url: '/information',
        template: '<ui-view />'
    })
        .state('information.rackOrShelf', {
            url: '/rackOrShelf',
            templateUrl: 'Scripts/html/rackOrShelfPartial.html'
        }).state('information.door', {
            url: '/door',
            templateUrl: 'Scripts/html/doorPartial.html'
        }).state('information.frame', {
            url: '/frame',
            templateUrl: 'Scripts/html/framePartial.html'
        });

Now you should be able to navigate to /information/door for example, or transition to the state name of information.door 现在,您应该能够导航到/information/door ,或转换为information.door的状态名称。

Angular Router allows us to handle that pretty well Angular Router使我们能够很好地处理

I think nested states the solution. 我认为嵌套状态的解决方案。

Kindly check here: 请在这里检查:

Different states for same URL #217 同一网址#217的不同状态

Re-use a URL for states #1096 为状态#1096重新使用URL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM