egg-flash

1.0.0 • Public • Published

egg-flash

NPM version build status Test coverage David deps Known Vulnerabilities npm download

flash messages for egg

Install

$ npm i egg-flash --save

Usage

// {app_root}/config/plugin.js
exports.flash = {
  enable: true,
  package: 'egg-flash',
};

Use ctx.flash() in your controller

// {app_root}/app/controller/home.js
exports.index = async ctx => {
  ctx.flash('info', 'Welcome');
  ctx.render('index', {
    title: 'Home'
  });
};
 
exports.addFlash = async ctx => {
  ctx.flash('info', 'Flash Message Added');
  ctx.redirect('/');
};

Access the messages in your views via locals.messages (Nunjucks in this case):

{% if messages.info %}
  {% for message in messages.info %}
    <div class="message info">
      <span>{{ message }}</span>
    </div>
  {% endfor %}
{% endif %}

Questions & Suggestions

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i egg-flash

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

5.8 kB

Total Files

16

Last publish

Collaborators

  • chunkai1312