I. Jump to the specified page after the specified time

By meta tag

<meta http-equiv="refresh" content="3; url=/">
Copy the code

The controller base class BaseController

You can encapsulate common methods in your application by customizing the Controller base class.

  1. Create a folder called core under the app folder and create base.js in it
'use strict';

const Controller = require('egg').Controller;

class BaseController extends Controller {
  async success() {
    await this.ctx.render('success')}}module.exports = BaseController;
Copy the code
  1. The controller that needs to use the base class method changes the controller inheritance source
'use strict';

const BaseController = require('.. /core/base.js');

class UserController extends BaseController {
  async doLogin() {
    console.log(this.ctx.request.body);
    await this.success(); }}module.exports = UserController;
Copy the code
  1. The encapsulated methods are already on this
await this.success();
Copy the code