# connect-pushstate

> Connect middleware that rewrites select requests to the site root, allowing your client-side pushstate router to handle them

Latest version **1.1.0** (published 2016-11-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install connect-pushstate
pnpm add connect-pushstate
yarn add connect-pushstate
bun add connect-pushstate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2016-11-21 |
| First published | 2013-12-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Brent Ertz |
| Maintainers | brentertz |
| Keywords | connect, middleware, rewrite, pushstate, routing |

## Links

- npm: https://www.npmjs.com/package/connect-pushstate
- Repository: https://github.com/brentertz/connect-pushstate
- Issues: https://github.com/brentertz/connect-pushstate/issues
- npm.io page: https://npm.io/package/connect-pushstate

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2016-11-21
- 1.0.0 — 2015-01-08
- 0.1.0 — 2013-12-08

## README

# connect-pushstate

Connect middleware that rewrites select requests to the site root, allowing your client-side pushstate router to handle them.

Requests including a file extension are left untouched so site assets like your images, stylesheets, and JavaScripts will load unaffected, while requests without a file extension, presumably pages or actions within your site, are rewritten to point at the root, with the original URL intact.

You can also specify regular expressions to specifically allow or disallow additional paths from being affected.

This functionality is commonly needed by single page web-apps.

## Getting Started

Install package

```shell
npm install connect-pushstate --save
```

Load the middleware by adding the following line of JavaScript.

```js
var pushState = require('connect-pushstate');
```

Add the `pushState` middleware call to your server definition, amongst your other middleware.

##### Options

The pushState method accepts an options object as an optional parameter with the following properties.

* __root__ - The location where requests will be rerouted to.  Defaults to '/'. e.g. `pushState({ root: '/foo' })`
* __allow__ - A pattern that will allow requests matching it to pass through without being redirected.  e.g. `pushState({ allow: '^/api' })`  You might need this option if your client app and API are on the same server.
* __disallow__ - A pattern that will disallow requests matching it to pass through without being redirected.  e.g. `pushState({ disallow: '^/version/1.2.3' })`

```js
'use strict';

var connect = require('connect');
var morgan = require('morgan');
var serveStatic = require('serve-static');
var pushState = require('connect-pushstate');
var port = process.env.PORT || 3000;

var app = connect()
.use(pushState())
.use(serveStatic('www/'))
.use(morgan('dev'))
.listen(port, function() {
	console.log('Application server stated on port', port);
});
```
_Note that [serve-static](https://www.npmjs.com/package/serve-static) is needed in order to actually serve your files._

## Examples

For a quick demo, see the examples directory, or run the test suite.

```shell
cd examples
node server.js
```

## Tests

Execute the test suite
```
npm test
```

## Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

## Release History
- 1.1.0 Add "disallow" option.  Add grunt package to devDependencies.
- 1.0.0 Introduce options object. Add "allow" option. Simplify directory structure. Update dependencies. Other minor housekeeping.
- 0.1.0 Initial release

---
_Source: https://npm.io/package/connect-pushstate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
