UI Router 条件 ui 视图? [英] UI Router conditional ui views?

查看:13
本文介绍了UI Router 条件 ui 视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想不出一个合理的方法来解决这个相当琐碎的问题.

I can't figure out a reasonable way, which doesn't feel like a hack, to solve this rather trivial problem.

我希望访客在访问网站索引时看到启动页面,并希望登录用户看到他们的个人资料,每个页面都有自己的模板和控制器.理想情况下,一个 url 会有两种状态,不知何故,我可以根据登录状态自动更改活动状态.这两个视图都有自己的嵌套视图,因此不能使用 ng-include(我假设).

I want a guest to see a splash page when they access the index of the website and a logged in user to see their profile, with each page having it's own template and controller. Ideally, there would be two states for one url, and somehow I would be able to automatically alter the active one depending on the loggin status. Both of these views will have their own nested views so ng-include cannot be used (I assume).

我对 Angular 和 ui 路由器还很陌生,我认为我可能忽略了一个简单的问题解决方案.

I'm quite new to angular and ui router and think I might be overlooking an easy solution to the problem.

是否可以使用命名视图和 ng-show 来完成?

Could it be done with named views and ng-show?

推荐答案

如果您使用的是 UI Router,只需创建三个状态:根状态,带有 '/' URL,以及两个没有 URL 的直系后代状态.在根状态的 onEnter 中,您检测用户的状态并相应地转换到正确的子状态.这看起来为两个子状态保持相同的 URL,但允许您必须使用单独的配置来分隔状态.

If you're using UI Router, just create three states: the root state, with the '/' URL, and two direct descendant states with no URLs. In the onEnter of the root state, you detect the state of the user and transition to the correct child state accordingly. This gives the appearance of keeping the same URL for both child states, but allows you to have to separate states with separate configurations.

这篇关于UI Router 条件 ui 视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆