Redirect and alter the query string for Rill.
npm install @rill/refresh-withUtility to redirect/refresh with an updated query string.
``console`
npm install @rill/refresh-with
`js
const app = require('rill')()
const refreshWith = require('@rill/refresh-with')
// Setup the middleware.
app.use(refreshWith())
// Use the 'res.refreshWith' utility.
// Example href is http://test.com/my-view?modal=hello&test=1modal
app.get('/my-view', ({ req, res }, next)=> {
// Example usecase of removing a modal from the querystring.
if (req.query.modal) {
res.refreshWith({ modal: '', success: true })
// Removes and adds success=truehttp://test.com/my-view?success=true&test=1
res.get('Location') // ->
}
})
// Example referrer is http://test.com/my-view?modal=hello&test=1modal
app.get('/from-somewhere-else', ({ req, res }, next)=> {
// Example usecase of redirecting to the previous page while unsetting a modal.
res.refreshWith({ modal: '', success: true }, { url: 'back', hash: '#top' })
// Removes and adds success=true to the referrerhttp://test.com/my-view?success=true&test=1
res.get('Location') // -> `
})
###ctx.res.refreshWith(setters:Object, options:Object)ctx.res.redirect
Similar to calling but will update the current querystring with setters and default the url to the current href.options.url
Specify the option as back to automatically redirect to the referrer page.
You can also specify options.alt for the fallback when using options.url = 'back'.
---
* Use npm test` to run tests.
Please feel free to create a PR!