登录后重定向到仪表板 [EMBER.JS]
Redirect to dashboard after login [EMBER.JS]
我想在登录到用户仪表板后重定向,我该怎么做?目前我有一个注册页面和登录页面,但在将其登录回登录和注册的主页后,我希望它转到仪表板,需要我 post 这里
的任何文件
更新:
controller/application.js
import Ember from 'ember';
export default Ember.Controller.extend({
session: Ember.inject.service('session'),
actions: {
invalidateSession() {
this.get('session').invalidate();
}
}
});
controller/login.js
import Ember from 'ember';
export default Ember.Controller.extend({
session: Ember.inject.service('session'),
actions: {
authenticate() {
let { identification, password } =
this.getProperties('identification', 'password');
this.get('session').authenticate('authenticator:oauth2',
identification, password).catch((reason) => {
this.set('errorMessage', reason.error || reason);
});
}
}
});
route/application.js
import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-
auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin, {
actions: {
invalidateSession() {
this.get('session').invalidate();
}
}
});
route/login.js
import Ember from 'ember';
export default Ember.Route.extend({
});
在将 login/pass 发送到后端的代码中,您可以使用 promise 成功回调来重定向,例如:
在您的路线中某处(申请路线或登录路线):
actions: {
checkAuth(email, password) {
let _this = this;
// Ajax call or service call
.....authenticate(email, password).then(function(data) {
// set current user
// do whatever you want
_this.transitionTo("dashboard"); // redirect to the dashboard route
});
}
}
将 routeAfterAuthentication
添加到您的申请途径:
export default Ember.Route.extend(ApplicationRouteMixin, {
routeAfterAuthentication: 'dashboard',
actions: {
invalidateSession() {
this.get('session').invalidate();
}
}
}
https://ember-simple-auth.com/api/classes/ApplicationRouteMixin.html
我想在登录到用户仪表板后重定向,我该怎么做?目前我有一个注册页面和登录页面,但在将其登录回登录和注册的主页后,我希望它转到仪表板,需要我 post 这里
的任何文件更新:
controller/application.js
import Ember from 'ember';
export default Ember.Controller.extend({
session: Ember.inject.service('session'),
actions: {
invalidateSession() {
this.get('session').invalidate();
}
}
});
controller/login.js
import Ember from 'ember';
export default Ember.Controller.extend({
session: Ember.inject.service('session'),
actions: {
authenticate() {
let { identification, password } =
this.getProperties('identification', 'password');
this.get('session').authenticate('authenticator:oauth2',
identification, password).catch((reason) => {
this.set('errorMessage', reason.error || reason);
});
}
}
});
route/application.js
import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-
auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin, {
actions: {
invalidateSession() {
this.get('session').invalidate();
}
}
});
route/login.js
import Ember from 'ember';
export default Ember.Route.extend({
});
在将 login/pass 发送到后端的代码中,您可以使用 promise 成功回调来重定向,例如:
在您的路线中某处(申请路线或登录路线):
actions: {
checkAuth(email, password) {
let _this = this;
// Ajax call or service call
.....authenticate(email, password).then(function(data) {
// set current user
// do whatever you want
_this.transitionTo("dashboard"); // redirect to the dashboard route
});
}
}
将 routeAfterAuthentication
添加到您的申请途径:
export default Ember.Route.extend(ApplicationRouteMixin, {
routeAfterAuthentication: 'dashboard',
actions: {
invalidateSession() {
this.get('session').invalidate();
}
}
}
https://ember-simple-auth.com/api/classes/ApplicationRouteMixin.html