简体   繁体   English

使用Angular UI-Router将状态作为Ionic Framework中的新路由处理

[英]Handle State as new Route in Ionic Framework with Angular UI-Router

I'm using the Ionic Framework with its AngularJS UI-Router and $stateProvider to handle different views in my app. 我正在将Ionic Framework及其AngularJS UI-Router和$ stateProvider用于处理我的应用程序中的不同视图。

However, I'm having trouble figuring out how to tell the $stateProvider that I got different "Main View's", with each having different Subviews. 但是,我很难弄清楚如何告诉$ stateProvider我得到了不同的“主视图”,每个视图都有不同的子视图。

When I'm on /#/home for example, and click on a link which sends me to /#/about , then /#/about doesn't get rendered as it's own, new view. 当我在/#/home ,例如,点击它发送给我一个链接/#/about ,那么/#/about没有得到渲染,因为它是自己的新观点。 Instead it transitions to it as it were a subpage of /#/home . 相反,它过渡到它,因为它是/#/home的子页面。

It works like it should when I replace $stateProvider with the AngularJS $routeProvider, but then all the transitions are gone. 当我用AngularJS $ routeProvider替换$ stateProvider时,它应该像应该的那样工作,但是所有转换都消失了。

I've created a Pen for you to take a look at it. 我创建了一支钢笔供您查看。

http://codepen.io/anon/pen/gBDFi http://codepen.io/anon/pen/gBDFi

There should be no transition between them. 它们之间不应有过渡。 Every "base" url should be a new "tab". 每个“基本” URL应为一个新的“标签”。

don't know if this is still relevant as it was posted February and I'm by no means a ng-pro but here is my attempt JSBinLink 不知道这是否仍然相关,因为它是二月份发布的,我绝不是ng-pro,但这是我的尝试JSBinLink

Two major things I did where to wrap the content in ion-tabs and add it in the stateProvider as an abstract state. 我做了两件主要的事情,将内容包装在ion-tabs中,并将其作为抽象状态添加到stateProvider中。

With this construct you have two independent tabs "Home", "About" - notice, no back button. 使用此结构,您有两个独立的选项卡“主页”,“关于”-注意,没有后退按钮。 However if you navigate to "Tom" within "About" - you get a back button. 但是,如果您导航到“关于”中的“汤姆”,则会显示返回按钮。

There are other ways to achieve something similar, one is to create child states and such. 还有其他方法可以实现类似的目的,一种是创建子状态等等。

I would recommend to check out the UI-Routers documentation. 我建议您查看UI-Routers文档。 It's mostly well written and very informative - there is also a create video of Tom Kindberg explaining the main concepts of it over here . 它写的很好,信息也很丰富-还有一个汤姆·金德伯格(Tom Kindberg)的创作视频在这里解释其主要概念。

Hope this helps. 希望这可以帮助。

Difference between $StateRouteProvider and $UrlRouteProvider .. $ StateRouteProvider和$ UrlRouteProvider之间的区别..

$UrlRouteProvider.otherwise(url); $ UrlRouteProvider.otherwise(url); -->route to given url. ->路由到给定的URL。

$StateRouteProvider.otherwise(state); $ StateRouteProvider.otherwise(state); -->route to given state. ->路由到给定状态。

So, if you are using ui-router then wherever view change is required use $state.go(). 因此,如果您使用的是ui-router,则无论何时需要更改视图,都请使用$ state.go()。 In a case of $location.path(URL) will work in a case like the transition to the independent state to current state. 在$ location.path(URL)的情况下,例如在从独立状态转换为当前状态的情况下,它将起作用。 If you are looking to route through states under the same parent then you have to use $state route. 如果要通过同一父级下的州进行路由,则必须使用$ state路由。

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

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