使用 Ember Simple Auth,如果用户在需要登录才能查看的页面上,我该如何重定向到登录页面?

With Ember Simple Auth, how do I redirect to a login page if user is on a page they need to be signed in to view?

使用 Ember Simple Auth 时,如果用户试图查看只有登录后才能访问的页面,我该如何将用户重定向到登录页面?

您只需在 Route

中导入 AuthenticatedRouteMixin
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';

并像这样使用它:

export default Ember.Route.extend(AuthenticatedRouteMixin);

这将使路由(及其所有子路由)在会话未通过身份验证时转换为可配置的登录路由。

更多信息here