egg-flash
v1.0.0
Published
flash messages for egg
Downloads
1
Readme
egg-flash
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.