目录结构
基类base.js
controller/admin/base.js
'use strict';
const Controller = require('egg').Controller;
class BaseController extends Controller {
async success(redirectUrl) {
// this.ctx.body = '成功'
await this.ctx.render('admin/public/success',{
redirectUrl:redirectUrl
})
}
async error(redirectUrl) {
// this.ctx.body = '失败'
await this.ctx.render('admin/public/error',{
redirectUrl:redirectUrl
})
}
}
module.exports = BaseController;
新增router
router.js
router.get('/admin/login', controller.admin.login.index);
router.get('/admin/doLogin', controller.admin.login.doLogin);
controller
controller/admin/login.js
其中的this.success('/admin/login')
由base.js
调用,实现登录成功和失败后的跳转
'use strict';
var BaseController = require('./base.js')
class LoginController extends BaseController {
async index() {
await this.ctx.render('admin/login')
}
async doLogin() {
await this.success('/admin/login')
}
}
module.exports = LoginController;
view
view/public/success.html
<%- include ../public/page_header.html %>
<%- include ../public/page_aside.html %>
操作成功!
如果您不做出选择,将在 3秒后跳转到第一个链接地址。