# micro-next

> Integrations between Micro and Next.js

Latest version **1.1.1** (published 2018-01-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install micro-next
pnpm add micro-next
yarn add micro-next
bun add micro-next
```

## 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.1 |
| Published | 2018-01-21 |
| First published | 2018-01-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 20 |
| Author | sergiodxa |
| Maintainers | sergiodxa |

## Links

- npm: https://www.npmjs.com/package/micro-next
- Repository: https://github.com/sergiodxa/micro-next
- Homepage: https://github.com/sergiodxa/micro-next#readme
- Issues: https://github.com/sergiodxa/micro-next/issues
- npm.io page: https://npm.io/package/micro-next

## Dependencies (3)

- [micro-route](https://npm.io/package/micro-route.md) ^2.5.0
- [querystring](https://npm.io/package/querystring.md) ^0.2.0
- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.26.0

## Recent versions

- 1.1.1 (latest) — 2018-01-21
- 1.1.0 — 2018-01-21
- 1.0.0 — 2018-01-20

## README

# micro-next

Integrations between Micro and Next.js

## Usage

Install it from npm:

```bash
yarn add micro-next
```

Create a `routes.json` file with a list of pages, similar to this one:

```json
[
  {
    "method": "GET",
    "path": "/blog",
    "page": "/blog/posts",
    "name": "blog-posts"
  },
  {
    "method": "GET",
    "path": "/blog/:post",
    "page": "/blog/post",
    "name": "blog-post"
  }
]
```

Create a `server.js` file with the following code:

```js
const routes = require("./routes.json");
const microNext = require("micro-next");

module.exports = microNext({
  routes,
  next: {
    dev: process.env.NODE_ENV !== "production"
  }
});
```

And if you want to easily integrate this client side create a `lib/get-page.js` file with the following content:

```js
import get from "micro-next/get";
import routes from "../routes.json";

export default get(routes);
```

Now you can use it with `next/link`:

```js
import Link from "next/link";
import getPage from "lib/get-page.js";

export default () => (
  <Link {...getPage("blog-post", { post: 1 })}>
    <a>Go to blog post 1</a>
  </Link>
);
```

## API

### `micro-next`

A function used to initialize a Next.js custom server with Micro.

* `routes` (`array`) The list of custom routes
* `next` (`object`) A Next.js [configuration object](https://github.com/zeit/next.js#custom-server-and-routing)

It returns a Micro-ready request handler which run `app.prepare` and setup the routes.

### `micro-next/get`

A function used to get the routes by the name already formated to be used with `next/link`.

* `routes` (`array`) The list of custom routes

This function returns a new function you can export and use to get the `href` and `as` to pass to `next/link`.

* `pageName` (`string`) The name of route as defined in your list of routes
* `params` (`object`) The parameters to use in the URL
* `query` (`object`) The query to add in the URL (default `{}`)

The function returns an object with the following data:

* `href` (`string`) The real path of the URL
* `as` (`as`) The URL to show in the browser

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