3.1.0 • Published 7 years ago

@rill/refresh-with v3.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Utility to redirect/refresh with an updated query string.

Installation

npm install @rill/refresh-with

Example

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=1`
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 `modal` and adds `success=true`
		res.get('Location') // -> `http://test.com/my-view?success=true&test=1`
	}
})

// Example `referrer` is `http://test.com/my-view?modal=hello&test=1`
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 `modal` and adds `success=true to the referrer`
	res.get('Location') // -> `http://test.com/my-view?success=true&test=1`
})

API

###ctx.res.refreshWith(setters:Object, options:Object) Similar to calling ctx.res.redirect but will update the current querystring with setters and default the url to the current href. Specify the options.url option as back to automatically redirect to the referrer page.

You can also specify options.alt for the fallback when using options.url = 'back'.


Contributions

  • Use npm test to run tests.

Please feel free to create a PR!

3.1.0

7 years ago

3.0.4

7 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.0.0

7 years ago

1.0.0

8 years ago

0.4.4

8 years ago

0.4.3

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago