Ember.js - 根URL可以链接到两个路由,一个用于认证用户,一个用于客户端? [英] Ember.js - Can the root url link to two routes, one for authenticated users and one for guests?

查看:63
本文介绍了Ember.js - 根URL可以链接到两个路由,一个用于认证用户,一个用于客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根路径 example.com 是否可以显示目标网页( application / index )没有登录用户,但是登录用户的个人资料页面( users / show

Is it possible for the root path, example.com, to display a landing page(application/index) for not logged in users but a profile page (users/show) for users who are logged in?

Guest user -> example.com -> application/index

Authenticated user -> example.com -> users/show

我知道这违反了Ember应用状态的理念,被url反映,仍然有人知道/这种情况是否可能?

I know that this goes against Ember's philosophy of the app state being reflected by the url, still, does anyone know if/how this situation is possible?

干杯!

推荐答案

是的,你可以这样做。首先,您应该检查应用程序路由的beforeModel中登录的用户。如果用户登录,则使用transitionTo方法将其转换到配置文件页面,否则将其转到登录页面。

Yes, You can do it. Firstly, you should check the user logged in or not in "beforeModel" of "application" route. If user is logged in then transits it to "profile" page using "transitionTo" method otherwise transits it to "login" page.

beforeModel: function(transition) {
    var user;
    //put here method to check if user is logged in or not
    if (!user) {
      //if no user then transist to login
      this.transitionTo('login');
    } else {
      //other wise to profile page
      this.transitionTo('profilePage');
    }
}

这篇关于Ember.js - 根URL可以链接到两个路由,一个用于认证用户,一个用于客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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